【发布时间】:2023-03-22 15:04:01
【问题描述】:
每次我尝试运行用于发送通知的 Test.php 文件时,都会收到错误消息:
Fatal error: Class 'Illuminate\Notifications\Notification' not found in /Users/Macbook/app/app/Http/Controllers/Test.php on line 12.
这是我的 Test.php 文件:
<?php
namespace App\Notifications;
// use app\vendor\laravel\framework\src\Illuminate\Notifications\Notification;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\User;
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 \Illuminate\Notifications\Messages\MailMessage
*/
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 存在。
【问题讨论】: