Laravel :notification使用笔记

php artisan make:notification PayFinish
php artisan notifications:table 创建通知表
//TestModel
namespace app\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
class TestModel extends Model
{
use Notifiable;
protected $table = ‘test’;
}
//PayFinish
public function via($notifiable)
{
return [‘database’];
}
//toDatabase和toArray格式化消息内容
public function toArray($notifiable)
{
return [
‘test_id’ => $this->id,
‘name’ => $this->data->name,
];
}
//使用
$user = TestModel::find(1);
//$user->notify(new PayFinish($user));
foreach ($user->notifications as $notification) {
print_r($notification->data);
}
foreach ($user->unreadNotifications as $notification) {
print_r($notification->data);
//$notification->markAsRead();//标记已读
}
//Notification::send($user, new PayFinish());



Tagged , . Bookmark the permalink.

Comments are closed.