Reputation: 11
I'm trying to implement a Laravel 5 queue which sends an new event mail to a mailing list. I found out you can use a Command for this but every time I try to execute this command I get an error exception (see below). The class I've written to do the mailing is the following
<?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);
}
);
}*/
}
}
Note: I commented out the mailing part to check if it wasn't that part which was malfunctioning.
From a controller I call the EventMailing Command like this:
public function sendMail($event,$array)
{
Queue::push(new EventMailing($event,$array));
}
When I trigger this function and I do a php artisan queue:work --verbose I get this. Can anyone help me out with this?
[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
Upvotes: 0
Views: 1048
Reputation: 548
Change
public function handle(EventMailing $command, User $user)
{
$event = $command->event;
print_r($event);
by
public function handle(User $user)
{
//event is in the constructor
$event = $this->event;
print_r($event);
Upvotes: 1