Befehl php artisan make:notification NameOfNotification
existiert nicht in Lumen.
Sie müssten dieses Paket importieren.
Quelle: https://stevethomas.com.au/php/using-laravel-notifications-in-lumen.html
Der erste Schritt ist erforderlich, die belichten/notifications Paket:
composer require illuminate/notifications
Vielleicht werden Sie require illuminate/support
, ich bin nicht zu 100%, wenn dies eine erforderliche Abhängigkeit für ist Benachrichtigungen. Wenn Sie Fehler bekommen, könnte dies der Grund sein.
Als nächstes registrieren Sie die Service-Provider in Bootstrap/app.php
$app->register(\Illuminate\Notifications\NotificationServiceProvider::class);
// optional: register the Facade
$app->withFacades(true, [
'Illuminate\Support\Facades\Notification' => 'Notification',
]);
Fügen Sie das Meldepflichtige Merkmal zu welchen auch immer Modellen, die Sie mögen, würden Benutzer offensichtlich, dass sein:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
}
schreiben Benachrichtigungen der Normaler Weg:
<?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
]);
}
}
Senden Sie Benachrichtigungen von Ihrer App auf die normale Weise:
$user->notify(new Notifications\SpaceshipHasLaunched($spaceship));
Ich bin mir nicht sicher, ob es diese Funktion für Lumen gibt ... Lumen ist ein API-Framework. In Laravel existiert diese Funktion seit Version 5.3, denke ich. – lewis4u
Ich benutze Version 5.5 – CoolCK
Laravel oder Lumen ??? – lewis4u