$data=Employee::create([
'first_name'=>$request->input('first_name'),
'last_name'=>$request->input('last_name'),
'username'=>$request->input('username'),
'email'=>$request->input('email'),
'password'=>$request->input('password'),
'confirm_password'=>$request->input('confirm_password'),
]);
$admin=Employee::find(1);
$admin->notify(new NotifyAdmin($data));
通知类
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Notifiable;
use App\Models\Employee;
class NotifyAdmin extends Notification implements ShouldQueue
{
use Queueable, Notifiable;
private $val;
public function __construct(Employee $employee)
{
$this->val=$data;
}
public function via($notifiable)
{
return ['database'];
}
public function toArray($notifiable)
{
return [
'username'=> $this->val->username
];
}
}
答案 0 :(得分:0)
你的问题是因为你在构造函数参数中写了 $employee 但是你使用了数据,所以数据不存在,把它改成这样:-
public function __construct(Employee $employee)
{
$this->val=$employee;
}