2013-07-25 30 views
5
Log::info('Sending email', array(
    'title' => $attributes['title'], 
    'recipient' => $attributes['email'] 
)); 

Mail::queue('emails.welcome', $attributes, function($message) use ($attributes) 
{ 
    $message 
     ->to($attributes['email']) 
     ->subject($attributes['title']); 
}); 

问题出在关闭被传递给Mail::queue。怎么了?这与in the docs完全相同。发送排队邮件时不允许“封闭”序列化

+1

你的'$ attributes'变量是什么?它是否包含“Paginator”对象?你能为我们“var_dump”吗? – fideloper

+0

这是确切的错误? '不允许'关闭序列化'? –

回答

1

那么,我假设$attributes是你想要传递给电子邮件视图welcome。如果是这样,那么你需要把它放在一个数组中。在这种情况下,应该是这样的:

Mail::queue('emails.welcome', array('attributes' => $attributes), function($message) use ($attributes) 
{ 
    $message 
     ->to($attributes['email']) 
     ->subject($attributes['title']); 
}); 

...这可能适合你! :D

+0

现在我如何访问这些属性? – Fractaliste

+0

@Fractaliste ...因为它是一个数组,它实际上是! :D –

+1

“属性”键在视图内成为var名称。比方说,为了争论,我有这个'array('atrr'=> $ attributes);',那么我必须在视图内调用它们,''atrr ['email' ]'。得到它了? –

1

我遇到了同样的错误信息。我的问题是我的$属性是一个Eloquent模型,我猜这是不可序列化的。我不得不改变:

Mail::queue('emails.welcome', array('attributes' => $attributes), function($message) use ($attributes)

$attrArray = $attributes->toArray(); Mail::queue('emails.welcome', array('attributes' => $attributes), function($message) use ($attrArray)

0

我知道这个职位是旧的,但最近我得到这个错误以及。原因是在邮件队列回调中放入了一个$ request实例。

Mail::queue('emails.welcome',$data,function(){ 

$email = $request->input('email'); // <- apparently this will cause a closure error 


}); 

我也从搜索中了解到,您不能将非序列化的数据放入关闭中。这包括雄辩的模型或对象。

-1

问题是在闭包中使用$ this。查看文件SerializableClosures.php和函数serialize()。 $ this-> to和$ this-> subject是对类的字段的引用,而不是在Closure中,所以要修复代码,您必须使它们成为局部变量并将它们传递给闭包。

相关问题