php - Laravel 8:未定义的属性:App\Notifications\ResetPassword::$queue
问题描述
我想为我的通知应用队列,所以我在我的通知中实现了它ResetPassword
:
class ResetPassword extends Notification implements ShouldQueue
然后我运行php artisan queue:table
并迁移它,以便jobs
在数据库中成功创建表。
并更改QUEUE_CONNECTION
为database
at.env
文件并重新运行php artisan serve
.
但是当我对此进行测试并单击重置密码链接时,必须将新的表格行添加到jobs
表格中,但事实并非如此。
而不是那个,这个错误返回:
ErrorException未定义属性: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;
}
}
解决方案
看起来你忘了Queueable
Trait
在你的notification
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
推荐阅读
- c# - 对多个 api 控制器的 Jmeter 负载测试
- python - Python - 在函数调用期间检测星号(*)
- html - Angular - 如何放置一个对象
在 BehaviorSubject 中 - java - 如何仅记录来自 WebClient 的 POST ant PATCH 请求
- css - 如何使用 CSS(在 Firefox 中)仅隐藏垂直滚动条?
- reactjs - 我的数据测试 ID 在那里,但我的测试找不到它反应酶开玩笑单元测试
- swiftui - 如何在 macOS 上更改禁用的 SwiftUI TextField 的背景和前景色
- java - 如何在java中从s3获取触发lambda的文件名
- c - 从 Windows 10 微过滤器驱动程序中的注册表读取
- c++ - 为什么 views::reverse 可以将 non-sized_range 转换为 size_range?