biniyam20
9 months ago
125
8
Laravel

Mailing inconsistency

Posted 9 months ago by biniyam20

When I use sync as my QUEUE_CONNECTION in my .env file, I get a different output compared to when I use a Redis connection. To be clear the issue is not that I am having trouble configuring Redis.

In both scenarios, I queue a job called SendReminderEmail whose handle is below


    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
      for($x = 0; $x < 1 ; $x++) // for each renter with an active rental
      {
        $renter = $this->renters[$x];

        \Log::info('email ' . $x . ' sent to ' . $renter->fname . ' at ' . $renter->email);

        //send them a reminder email
        \Mail::to($renter->email)->cc('[email protected]')
                        ->send(new ReturnReminder($renter, $renter->active_rented_listings));
      }
    }

My ReturnReminder mailable is quite simple, it just makes the renter and rented_listings properties available.

class ReturnReminder extends Mailable
{
    use Queueable, SerializesModels;

    public $renter;
    public $rented_listings;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($renter, $active_rented_listings)
    {
        $this->renter = $renter;
        $this->rented_listings = $active_rented_listings;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('[email protected]')
                     ->subject('Textbook Return Reminder')
                     ->markdown('mail.return-reminder');
    }
}

Now my issue comes in the actual rendering of the mail. When I use sync, the rented_listings are displayed in the mail, but not when I use redis. Interestingly, the $renter variable works in both scenarios, it's just the $rented_listings one that don't show in the mail. Any guidance/tips would be appreciated.

@component('mail::message')
# Introduction

Dear, {{$renter->fname}}

This is a reminder that the book(s) you rented are required to be returned. Here is a list of the rented books.

@component('mail::table')
| Title         | Author        | Condition  |
| ------------- |:-------------:| --------:|
@foreach ($rented_listings as $rented_listing)
| {{$rented_listing->listing->title}} | {{$rented_listing->listing->author}}| @include('partials.condition') |
@endforeach
@endcomponent


@endcomponent

Please sign in or create an account to participate in this conversation.