moh_abk's avatar

Passing Eloquent data to Mail Job/Queue - Lumen/Laravel

I'm trying to pass data to my job queue in Lumen with an eloquent model.

I'm getting the error trying to get property of non-object

This is my Job class

<?php

namespace App\Jobs;

use App;

class CustomerSignupEmailJob extends Job
{

    protected $getUser;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($getUser)
    {
        $this->user = $getUser;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        $mailer = app()->make('mailer');

        $mailer->send('emails.backend-customer-signup', ['user' => $this->getUser] , function ($message) {
            $message->from('xxx@xxx.com', 'Laravel');
            $message->to('xxx@gmail.com')->cc('xxx@yahoo.co.uk');
        });
    }
}

Mail expects an array as the second data

This is my controller code;

$getUser = Customer::where('email', $email)->first();
$job1 = (new CustomerSignupEmailJob($getUser));
$this->dispatch($job1);

You can see I'm fetching Customer as $getUser and passing it.

This is my email view;

Customer First Name: {{$user->first_name}}
Customer Last Name: {{$user->last_name}}
Customer Email: {{$user->email}}
Customer Phone Number: {{$user->mobile_phone}}
Customer Address Line 1: {{$user->address_line1}}
Customer Address Line 2: {{$user->address_line2}}
Customer Address Line 3: {{$user->address_line3}}
Customer Location: {{$user->location_id}}
Customer City: {{$user->city_id}}

I'm confused about how data is passed and accessed in the job class Any advice appreciated.

0 likes
1 reply
boarder212's avatar

It should be protected $user instand of $getUser in your Job class

Please or to participate in this conversation.