问题描述
我希望在每次注册新用户后都收到电子邮件通知,但是在创建PHP artisan make:notification Taskcompleted
并在我的控制台中添加Notification::route('mail','admin@gmail.com')->notify(new TaskCompleted());
之后
public function store(Request $request){
$employee = request()->validate([
'employee_id' => 'required|max:250','name' => 'required|max:100','place_of_birth' => 'nullable|max:100',]);
Notification::route('mail','admin@gmail.com')->notify(new TaskCompleted());
我一直收到此错误
Trying to access array offset on value of type null
我已经导入了必要的类,并使用mailtrap配置了.env文件,仍然出现相同的错误
任务完成的文件
<?PHP
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class TaskCompleted extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action',url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
解决方法
好的,我得到了我在laravel 5.5上使用PHP 7.4的解决方案,所以我现在将其降级到PHP 7.2可以正常工作