命令 "make:notification" 未定义。 |流明 5.5
Command "make:notification" is not defined. | Lumen 5.5
在Lumen开发推送通知应用的过程中,需要运行 php artisan
命令进行通知。当我运行 php artisan
make:notification
(php artisan make:notification
)命令不可用。我收到以下错误。
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "make:notification" is not defined
.
Did you mean one of these?
make:migration
make:seeder
请帮我解决这个问题。
谢谢
Lumen 中不存在命令 php artisan make:notification NameOfNotification
。
您必须导入该包。
来源:https://stevethomas.com.au/php/using-laravel-notifications-in-lumen.html
第一步需要 illuminate/notifications 包:
composer require illuminate/notifications
也许你会 require illuminate/support
,如果这是通知所需的依赖项,我不是 100%。如果您遇到错误,这可能就是原因。
接下来,在bootstrap/app中注册服务提供商。php
$app->register(\Illuminate\Notifications\NotificationServiceProvider::class);
// optional: register the Facade
$app->withFacades(true, [
'Illuminate\Support\Facades\Notification' => 'Notification',
]);
将 Notifiable 特征添加到您喜欢的任何模型,User 将是一个明显的特征:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
}
以正常方式写通知:
<?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
]);
}
}
以正常方式从您的应用发送通知:
$user->notify(new Notifications\SpaceshipHasLaunched($spaceship));
在Lumen开发推送通知应用的过程中,需要运行 php artisan
命令进行通知。当我运行 php artisan
make:notification
(php artisan make:notification
)命令不可用。我收到以下错误。
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "make:notification" is not defined
.
Did you mean one of these?
make:migration
make:seeder
请帮我解决这个问题。 谢谢
Lumen 中不存在命令 php artisan make:notification NameOfNotification
。
您必须导入该包。
来源:https://stevethomas.com.au/php/using-laravel-notifications-in-lumen.html
第一步需要 illuminate/notifications 包:
composer require illuminate/notifications
也许你会 require illuminate/support
,如果这是通知所需的依赖项,我不是 100%。如果您遇到错误,这可能就是原因。
接下来,在bootstrap/app中注册服务提供商。php
$app->register(\Illuminate\Notifications\NotificationServiceProvider::class);
// optional: register the Facade
$app->withFacades(true, [
'Illuminate\Support\Facades\Notification' => 'Notification',
]);
将 Notifiable 特征添加到您喜欢的任何模型,User 将是一个明显的特征:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
}
以正常方式写通知:
<?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
]);
}
}
以正常方式从您的应用发送通知:
$user->notify(new Notifications\SpaceshipHasLaunched($spaceship));