Command php artisan make:notification NameOfNotification
does not exist in Lumen.
You would have to import that package.
Source: https://stevethomas.com.au/php/using-laravel-notifications-in-lumen.html
The first step is requiring the illuminate/notifications package:
composer require illuminate/notifications
Maybe you will require illuminate/support
, i'm not 100% if this is a required dependency for notifications. If you get errors this might be why.
Next, register the service provider in bootstrap/app.php
$app->register(\Illuminate\Notifications\NotificationServiceProvider::class);
// optional: register the Facade
$app->withFacades(true, [
'Illuminate\Support\Facades\Notification' => 'Notification',
]);
Add the Notifiable trait to whichever models you like, User would be an obvious one:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
}
Write notifications the normal way:
<?php
namespace App\Notifications;
use App\Spaceship;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
class SpaceshipHasLaunched extends Notification
{
use Queueable;
/** @var Spaceship */
public $spaceship;
/**
* @param Spaceship $spaceship
*/
public function __construct(Spaceship $spaceship)
{
$this->spaceship = $spaceship;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Spacheship has launched!')
->markdown('mail.spaceship', [
'spaceship' => $this->spaceship
]);
}
}
Send notifications from your app the normal way:
$user->notify(new Notifications\SpaceshipHasLaunched($spaceship));