在队列执行中反序列化用户对象时发生错误:
[2016-12-20 21:10:01] production.ERROR: Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\User]. in /var/www/virtual/bob/bobnet/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:210
Stack trace:
#0 /var/www/virtual/bob/bobnet/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(45): Illuminate\Database\Eloquent\Builder->findOrFail(137)
如果我跑
\App\User::findOrFail(137)
找到正确的用户没有错误。直到几周,一切都运行良好。就像我的开发系统上的反序列化一样。 有谁知道出了什么问题?
通知:
<?php
namespace App\Mail;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
class GuideNotification extends Mailable
{
use Queueable, SerializesModels;
// Once the data has been set to a public property, it will automatically be available in the view
private $template;
public $user;
public $tour;
public $pivot;
public $sender;
public $date;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($template = 'emails.status_update', \App\User $user, \App\Tour $tour, $pivot, \App\User $sender = null)
{
$this->template = $template;
$this->user = $user;
$this->tour = $tour;
$this->date = new Carbon($tour->start);
$this->pivot = $pivot;
if ($sender) {
$this->sender = $sender->fullName();
}
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->to($this->user->email)
->cc(config('bob.bcc_mail'), 'BoB')
->subject($this->generateSubject())
->view($this->template);
}
protected function generateSubject()
{
switch ($this->template) {
case 'emails.request':
return 'Guide Anfrage ' . $this->tour->name . ' am ' . $this->date->format('d.m.Y') . ' um ' . $this->date->format('H:i') . ' Uhr (ID ' . $this->tour->id . ')';
break;
case 'emails.confirmation':
return 'Guide Bestätigung ' . $this->tour->name . ' am ' . $this->date->format('d.m.Y') . ' um ' . $this->date->format('H:i') . ' Uhr (ID ' . $this->tour->id . ')';
break;
case 'emails.change':
return 'Guide Änderung ' . $this->tour->name . ' am ' . $this->date->format('d.m.Y') . ' um ' . $this->date->format('H:i') . ' Uhr (ID ' . $this->tour->id . ')';
break;
case 'emails.freesale':
return 'Guide Bestätigung "geschnappte" ' . $this->tour->name . ' am ' . $this->date->format('d.m.Y') . ' um ' . $this->date->format('H:i') . ' Uhr (ID ' . $this->tour->id . ')';
break;
default:
return 'Guide Statusupdate ' . $this->tour->name . ' am ' . $this->date->format('d.m.Y') . ' um ' . $this->date->format('H:i') . ' Uhr (ID ' . $this->tour->id . ')';
break;
}
}
}
答案 0 :(得分:0)
长话短说:
由于某些环境变量和执行上下文,队列使用不同的php版本,导致此错误。在强制使用正确的php版本后,一切正常。