Reputation: 21
Every time I try to run my Test.php file, which is meant to send a notification, I am getting the error message:
Fatal error: Class 'Illuminate\Notifications\Notification' not found in /Users/Macbook/app/app/Http/Controllers/Test.php on line 12
.
Here is my Test.php file:
<?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
];
}
}
I am trying to send notifications using the Database method. Could anyone help me out? It's just odd because I am sure that Illuminate\Notifications\Notification exists.
Upvotes: 1
Views: 5406
Reputation: 504
Notifications may be sent in two ways: using the notify method of the Notifiable trait or using the Notification facade.
https://laravel.com/docs/5.3/notifications#sending-notifications
Option 1
You can use notify()
method:
$user->notify(new AgendamentoPendente(1));
Also, make sure User class uses Notifiable trait:
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
Option 2
Using facade with full namespace:
\Notification::send($user, new AgendamentoPendente(1));
Upvotes: 1