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

Laravel 8: Undefined property: App\Notifications\ResetPassword::$queue

我希望 tp apply queue 用于我的通知,所以我在 ResetPassword:

的通知中实现了它
class ResetPassword extends Notification implements ShouldQueue

然后我 运行 php artisan queue:table 并迁移它所以 table jobs 在数据库中成功创建。

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

但是当我对此进行测试并单击重置密码 link 时,必须将新的 table 行添加到 jobs table 但它没有。

而不是那个错误 returns:

ErrorException Undefined property: App\Notifications\ResetPassword::$queue ...\notification\vendor\laravel\framework\src\Illuminate\Notifications\NotificationSender.php:195

那么这里出了什么问题?我该如何解决这个问题?

非常感谢你们的任何想法或建议...

提前致谢。

更新 #1:

ResetPassword.php:

<?php

namespace App\Notifications;

use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Lang;

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 \Illuminate\Notifications\Messages\MailMessage
     */
    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

中使用 Queueable Trait
use Illuminate\Bus\Queueable;
class ResetPassword extends Notification implements ShouldQueue
{

   use Queueable;

Queueable trait 有属性 $queue

参考:https://laravel.com/docs/8.x/notifications#queued-notifications-and-database-transactions