0
我试图实现一个Laravel 5队列,它发送一个新的事件邮件到邮件列表。我发现你可以使用Command来做这件事,但每次我尝试执行这个命令时,我都会得到一个错误异常(见下文)。我已经写做邮件类是以下Laravel命令队列异常
<?php namespace App\Commands;
use Illuminate\Support\Facades\App;
use \App\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class EventMailing extends Command implements SelfHandling, ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
/**
* Create a new command instance.
*
* @return void
*/
public $event;
public $recipients;
public function __construct(Event $event, $recipients)
{
$this->event=$event;
$this->recipients=$recipients;
}
/**
* Execute the command.
*
* @return void
*/
public function handle(EventMailing $command, User $user)
{
$event = $command->event;
print_r($event);
/* foreach ($this->recipients as $recipient) {
Mail::send('emails.event', $event,
function($message) use ($event,$recipient)
{
$message->from('[email protected]', 'GSE BeLux');
$message->subject('New event: '.$event->name);
$message->to($recipient);
}
);
}*/
}
}
注:我注释掉的邮件部分来检查,如果不是那部分是不正常。
从控制器我称之为EventMailing命令是这样的:
public function sendMail($event,$array)
{
Queue::push(new EventMailing($event,$array));
}
当我触发这个功能,我做了PHP的工匠队列:工作--verbose 我得到这个。任何人都可以帮我解决这个问题吗?
[ErrorException]
unserialize(): Function spl_autoload_call() hasn't defined the class it was called for
Exception trace:
() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:36
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at n/a:n/a
unserialize() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:36
Illuminate\Queue\CallQueuedHandler->call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:126
Illuminate\Queue\Jobs\Job->resolveAndFire() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Jobs/BeanstalkdJob.php:51
Illuminate\Queue\Jobs\BeanstalkdJob->fire() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:207
Illuminate\Queue\Worker->process() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:159
Illuminate\Queue\Worker->pop() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:107
Illuminate\Queue\Console\WorkCommand->runWorker() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:67
Illuminate\Queue\Console\WorkCommand->fire() at n/a:n/a
call_user_func_array() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/Container.php:523
Illuminate\Container\Container->call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:115
Illuminate\Console\Command->execute() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:253
Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:101
Illuminate\Console\Command->run() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Application.php:874
Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:90
Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/artisan:36
你曾经能够解决这个问题?我正在处理同样的错误 - 即使是最简单的命令 – NightMICU 2015-04-03 19:51:47
也没有真正用这种方法解决。以旧的方式,并创建了一个队列“EventMailing”,并从控制器上推送我的作业。在队列类中,我创建了一个处理邮件作业的“fire”方法。如果更多的人为此付出努力,我会在我的网站上发布一篇博文,请问我。 – jelledb 2015-04-07 07:16:42