将Eloquent数据传递给Mail Job / Queue - Lumen / Laravel

时间:2016-02-11 12:40:11

标签: laravel laravel-5 lumen

我尝试使用job模型将数据传递到Lumen中的eloquent个队列。

我收到错误trying to get property of non-object

这是我的Job类

<?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期望数组作为第二个数据

这是我的控制器代码;

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

您可以看到我将Customer取为$getUser并传递给它。

这是我的电子邮件视图;

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}}

我对如何在job class中传递和访问数据感到困惑 任何建议表示赞赏。

1 个答案:

答案 0 :(得分:1)

在构造函数中更改

<script>
    $.getJSON('https://www.googleapis.com/youtube/v3/videospart=statistics&id=Qq7mpb-hCBY&key=Your-Api-Key', function(data) {
        console.log("viewCount: ", data.items[ 0 ].statistics.viewCount);
    });
</script>

$this->user = $getUser 

在处理程序中,使用队列。

$this->getUser = $getUser