如何修复找不到类'IlluminateNotificationsNotification'?



每次我试图运行我的Test.php文件(用于发送通知(时,我都会收到错误消息:CCD_ 1。

这是我的Test.php文件:

<?php
namespace AppNotifications;
// use appvendorlaravelframeworksrcIlluminateNotificationsNotification;
use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
use Notification;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;
use AppUser;
class Test extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public $test;
public function __construct($test)
{
$this->test = $test;
}
/**
* Get the notification's delivery channels.
*
* @param  mixed  $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*
* @param  mixed  $notifiable
* @return IlluminateNotificationsMessagesMailMessage
*/
public function toMail($notifiable)
{
/** 
$url = url('/test/'.$this->test->id);
return (new MailMessage)
->greeting('Hello!')
->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 toDatabase($notifiable)
{
return [
'data' => 'You have a new notification.',
'from' => $this->message->name,
'name'=> $this->message->email,
'subject' => $this->message->subject,
'body' => $this->message->body
];
}
}

我正在尝试使用数据库方法发送通知。有人能帮我吗?这很奇怪,因为我确信Illuminate\Notifications\Notification存在。

通知可以通过两种方式发送:使用Notified trait的notify方法或使用Notification facade。

https://laravel.com/docs/5.3/notifications#sending-通知

选项1

您可以使用notify()方法:

$user->notify(new AgendamentoPendente(1));

此外,请确保User类使用可通知特性:

use IlluminateNotificationsNotifiable;
class User extends Authenticatable
{
use Notifiable;

选项2

使用具有完整名称空间的facade:

Notification::send($user, new AgendamentoPendente(1));

最新更新