Laravel 8:未定义的属性:App\Notifications\ResetPassword::$queue



我想为我的通知应用队列,所以我在我的通知中实现了它,ResetPassword:

class ResetPassword extends Notification implements ShouldQueue

然后我运行了php artisan queue:table并对其进行了迁移,从而在DB中成功创建了表jobs

并在.env文件中将QUEUE_CONNECTION更改为database,然后重新运行php artisan serve

但当我测试并点击重置密码链接时,必须向jobs表中添加一个新的表行,但它没有。

相反,这个错误返回:

错误异常未定义的属性:App\Notifications\ResetPassword::$queue…\notification\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php:195

那么这里出了什么问题?如何解决此问题?

我真的很感激你们的任何想法或建议。。。

提前谢谢。

更新#1

ResetPassword.php:

<?php
namespace AppNotifications;
use IlluminateNotificationsMessagesMailMessage;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsNotification;
use IlluminateSupportFacadesLang;
class ResetPassword extends Notification implements ShouldQueue
{
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* The callback that should be used to build the mail message.
*
* @var Closure|null
*/
public static $toMailCallback;
/**
* Create a notification instance.
*
* @param  string  $token
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's channels.
*
* @param  mixed  $notifiable
* @return array|string
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param  mixed  $notifiable
* @return IlluminateNotificationsMessagesMailMessage
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
return (new MailMessage)
->subject('subject goes here')
->line('This email is sent to you')
->action(Lang::get('Reset Password'), url(config('app.url').route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
->line(Lang::get('Until the next 60 minutes you can use this link', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
->line(Lang::get('If you did not request a password reset, no further action is required.'));
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param  Closure  $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}

看起来好像忘记在notification中使用QueueableTrait

use IlluminateBusQueueable;
class ResetPassword extends Notification implements ShouldQueue
{
use Queueable;

Queueable trait具有$queue性质

参考编号:https://laravel.com/docs/8.x/notifications#queued-通知和数据库事务

最新更新