Laravel命令队列异常

时间:2015-03-13 12:39:08

标签: php exception laravel

我正在尝试实现一个Laravel 5队列,该队列将新的事件邮件发送到邮件列表。我发现你可以使用一个命令,但每次我尝试执行这个命令时都会出现错误异常(见下文)。我编写的用于邮寄的课程如下:

<?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('info@gsebelux.org', 'GSE BeLux');
                    $message->subject('New event: '.$event->name);
                    $message->to($recipient);
                }
            );
        }*/
    }

}

注意:我评论了邮寄部分,以检查是不是那个发生故障的部分。

我从控制器调用EventMailing命令,如下所示:

public function sendMail($event,$array)
{
    Queue::push(new EventMailing($event,$array));
} 

当我触发此功能并执行php工匠队列时:work --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

1 个答案:

答案 0 :(得分:1)

更改

public function handle(EventMailing $command, User $user)
{
    $event = $command->event;

    print_r($event);

通过

public function handle(User $user)
{
    //event is in the constructor
    $event = $this->event;

    print_r($event);