我有3个不同的作业被推送到队列发送邮件(新闻,欢迎,重置密码)。
新闻和欢迎工作正常,所以我创建了相同的最后一个,但它在存储/框架/视图中抛出错误,我发送的变量是未定义的,这不是真的,因为我做了dd( )在dispatch()之前查看是否设置了变量。
我正在使用带有数据库驱动程序和主管的队列
控制器:
public function sendRecoverLink(Request $request) {
$this->validate($request, [
'email' => 'required|email'
]);
$user = User::where([
'email' => $request->email,
])->first();
if (! $user){
return response(['Message' => "No such user"], 403);
}
$url = URL::current(); //some url as example
//token crypting and inserting to database
dispatch(new SendResetEmail($user, $url)); //sends mail
return response(['message' => 'Send'], 200);
}
工作班
class SendResetEmail extends Job
{
protected $user;
protected $url;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($user, $url)
{
$this->user = $user;
$this->url = $url;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::to($this->user->email)->send(new Reset($this->user->first_name, $url));
}
}
邮件类
class Reset extends Mailable
{
use Queueable, SerializesModels;
protected $user;
protected $url;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $user, $url)
{
$this->user = $user;
$this->url = $url;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.reset')
->with([
'name' => $this->user->first_name,
'link' => $this->url,
]);
}
}
视图
@component('mail::message')
# {{$name}},
reset your password by clicking this link{{$link}}
@endcomponent
数据库错误
ErrorException: Undefined variable: user in /var/www/eventmanager/storage/framework/views/03cb8c67266d078a3839b8266816206d466825f2.php:2
Stack trace:
#0 /var/www/eventmanager/storage/framework/views/03cb8c67266d078a3839b8266816206d466825f2.php(2): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(8, 'Undefined varia...', '/var/www/eventm...', 2, Array)
#1 /var/www/eventmanager/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/var/www/eventm...')
#2 /var/www/eventmanager/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/eventm...', Array)
#3 /var/www/eventmanager/vendor/illuminate/view/View.php(137): Illuminate\View\Engines\CompilerEngine->get('/var/www/eventm...', Array)
#4 /var/www/eventmanager/vendor/illuminate/view/View.php(120): Illuminate\View\View->getContents()
#5 /var/www/eventmanager/vendor/illuminate/view/View.php(85): Illuminate\View\View->renderContents()
#6 /var/www/eventmanager/vendor/illuminate/mail/Markdown.php(61): Illuminate\View\View->render()
#7 /var/www/eventmanager/vendor/illuminate/mail/Mailable.php(217): Illuminate\Mail\Markdown->render('emails.reset', Array)
#8 /var/www/eventmanager/vendor/illuminate/mail/Mailable.php(189): Illuminate\Mail\Mailable->buildMarkdownView()
#9 /var/www/eventmanager/vendor/illuminate/mail/Mailable.php(119): Illuminate\Mail\Mailable->buildView()
#10 /var/www/eventmanager/vendor/illuminate/mail/Mailer.php(250): Illuminate\Mail\Mailable->send(Object(Illuminate\Mail\Mailer))
#11 /var/www/eventmanager/vendor/illuminate/mail/Mailer.php(205): Illuminate\Mail\Mailer->sendMailable(Object(App\Mail\Reset))
#12 /var/www/eventmanager/vendor/illuminate/mail/PendingMail.php(99): Illuminate\Mail\Mailer->send(Object(App\Mail\Reset))
#13 /var/www/eventmanager/app/Jobs/SendResetEmail.php(28): Illuminate\Mail\PendingMail->send(Object(App\Mail\Reset))
#14 [internal function]: App\Jobs\SendResetEmail->handle()
#15 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
#16 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#17 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#18 /var/www/eventmanager/vendor/illuminate/container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#19 /var/www/eventmanager/vendor/illuminate/bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#20 /var/www/eventmanager/vendor/illuminate/pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendResetEmail))
#21 /var/www/eventmanager/vendor/illuminate/pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendResetEmail))
#22 /var/www/eventmanager/vendor/illuminate/bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#23 /var/www/eventmanager/vendor/illuminate/queue/CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendResetEmail), false)
#24 /var/www/eventmanager/vendor/illuminate/queue/Jobs/Job.php(76): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#25 /var/www/eventmanager/vendor/illuminate/queue/Worker.php(320): Illuminate\Queue\Jobs\Job->fire()
#26 /var/www/eventmanager/vendor/illuminate/queue/Worker.php(270): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#27 /var/www/eventmanager/vendor/illuminate/queue/Worker.php(114): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#28 /var/www/eventmanager/vendor/illuminate/queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#29 /var/www/eventmanager/vendor/illuminate/queue/Console/WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#30 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#31 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
#32 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#33 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#34 /var/www/eventmanager/vendor/illuminate/container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#35 /var/www/eventmanager/vendor/illuminate/console/Command.php(183): Illuminate\Container\Container->call(Array)
#36 /var/www/eventmanager/vendor/symfony/console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#37 /var/www/eventmanager/vendor/illuminate/console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#38 /var/www/eventmanager/vendor/symfony/console/Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /var/www/eventmanager/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /var/www/eventmanager/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 /var/www/eventmanager/vendor/illuminate/console/Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 /var/www/eventmanager/vendor/laravel/lumen-framework/src/Console/Kernel.php(84): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 /var/www/eventmanager/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#44 {main}
Next ErrorException: Undefined variable: user (View: /var/www/eventmanager/resources/views/emails/reset.blade.php) in /var/www/eventmanager/storage/framework/views/03cb8c67266d078a3839b8266816206d466825f2.php:2
Stack trace:
#0 /var/www/eventmanager/vendor/illuminate/view/Engines/PhpEngine.php(45): Illuminate\View\Engines\CompilerEngine->handleViewException(Object(ErrorException), 0)
#1 /var/www/eventmanager/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/eventm...', Array)
#2 /var/www/eventmanager/vendor/illuminate/view/View.php(137): Illuminate\View\Engines\CompilerEngine->get('/var/www/eventm...', Array)
#3 /var/www/eventmanager/vendor/illuminate/view/View.php(120): Illuminate\View\View->getContents()
#4 /var/www/eventmanager/vendor/illuminate/view/View.php(85): Illuminate\View\View->renderContents()
#5 /var/www/eventmanager/vendor/illuminate/mail/Markdown.php(61): Illuminate\View\View->render()
#6 /var/www/eventmanager/vendor/illuminate/mail/Mailable.php(217): Illuminate\Mail\Markdown->render('emails.reset', Array)
#7 /var/www/eventmanager/vendor/illuminate/mail/Mailable.php(189): Illuminate\Mail\Mailable->buildMarkdownView()
#8 /var/www/eventmanager/vendor/illuminate/mail/Mailable.php(119): Illuminate\Mail\Mailable->buildView()
#9 /var/www/eventmanager/vendor/illuminate/mail/Mailer.php(250): Illuminate\Mail\Mailable->send(Object(Illuminate\Mail\Mailer))
#10 /var/www/eventmanager/vendor/illuminate/mail/Mailer.php(205): Illuminate\Mail\Mailer->sendMailable(Object(App\Mail\Reset))
#11 /var/www/eventmanager/vendor/illuminate/mail/PendingMail.php(99): Illuminate\Mail\Mailer->send(Object(App\Mail\Reset))
#12 /var/www/eventmanager/app/Jobs/SendResetEmail.php(28): Illuminate\Mail\PendingMail->send(Object(App\Mail\Reset))
#13 [internal function]: App\Jobs\SendResetEmail->handle()
#14 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
#15 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#16 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#17 /var/www/eventmanager/vendor/illuminate/container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#18 /var/www/eventmanager/vendor/illuminate/bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#19 /var/www/eventmanager/vendor/illuminate/pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendResetEmail))
#20 /var/www/eventmanager/vendor/illuminate/pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendResetEmail))
#21 /var/www/eventmanager/vendor/illuminate/bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 /var/www/eventmanager/vendor/illuminate/queue/CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendResetEmail), false)
#23 /var/www/eventmanager/vendor/illuminate/queue/Jobs/Job.php(76): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#24 /var/www/eventmanager/vendor/illuminate/queue/Worker.php(320): Illuminate\Queue\Jobs\Job->fire()
#25 /var/www/eventmanager/vendor/illuminate/queue/Worker.php(270): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#26 /var/www/eventmanager/vendor/illuminate/queue/Worker.php(114): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#27 /var/www/eventmanager/vendor/illuminate/queue/Console/WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#28 /var/www/eventmanager/vendor/illuminate/queue/Console/WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#29 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#30 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(29): call_user_func_array(Array, Array)
#31 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#32 /var/www/eventmanager/vendor/illuminate/container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#33 /var/www/eventmanager/vendor/illuminate/container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#34 /var/www/eventmanager/vendor/illuminate/console/Command.php(183): Illuminate\Container\Container->call(Array)
#35 /var/www/eventmanager/vendor/symfony/console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#36 /var/www/eventmanager/vendor/illuminate/console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#37 /var/www/eventmanager/vendor/symfony/console/Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /var/www/eventmanager/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /var/www/eventmanager/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /var/www/eventmanager/vendor/illuminate/console/Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 /var/www/eventmanager/vendor/laravel/lumen-framework/src/Console/Kernel.php(84): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 /var/www/eventmanager/artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 {main}
答案 0 :(得分:0)
由于某种原因,队列运行旧代码,我必须做的是php artisan queue:restart
并且它已修复