命令“make:notification”未定义。 | 流明5.5
In the process of developing push notification application in Lumen, it is needed to run php artisan
command to make notifications. When I run php artisan
make:notification
(php artisan make:notification
)command is not available. I get the following error.
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "make:notification" is not defined
.
Did you mean one of these?
make:migration
make:seeder
Please help me to solve this issue. thanks
在Lumen中开发推送通知应用程序的过程中,需要运行 请帮我解决这个问题。
thanks p>
div> php artisan code >命令发出通知。 当我运行
php artisan code>
make:notification code>(
php artisan make:notification code>)命令不可用时。 我收到以下错误。 p>
[Symfony \ Component \ Console \ Exception \ CommandNotFoundException]
code> pre>
命令“make:notification”未定义 code>。 p>
您的意思是其中之一吗?
make:migration
make:seeder
代码> pre>
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));