未定义命令“ make:notification”。| 流明5.5

0 php notifications laravel lumen

在流明开发推送通知应用程序的过程中,需要运行php artisan命令进行通知。当我运行php artisan make:notificationphp artisan make:notification)命令时不可用。我收到以下错误。

 [Symfony\Component\Console\Exception\CommandNotFoundException]
Run Code Online (Sandbox Code Playgroud)

Command "make:notification" is not defined

 Did you mean one of these?
      make:migration
      make:seeder
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。谢谢

lew*_*s4u 5

php artisan make:notification NameOfNotification流明中不存在命令。

您将必须导入该软件包。

资料来源:https : //stevethomas.com.au/php/using-laravel-notifications-in-lumen.html


第一步是需要照明/通知包:

composer require illuminate/notifications
Run Code Online (Sandbox Code Playgroud)

也许您会的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',
]);
Run Code Online (Sandbox Code Playgroud)

将“可通知”特征添加到您喜欢的任何模型中,“用户”将是显而易见的一个:

<?php 

namespace App;

use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;
}
Run Code Online (Sandbox Code Playgroud)

正常编写通知:

<?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
            ]);
    }
}
Run Code Online (Sandbox Code Playgroud)

以常规方式从您的应用发送通知:

$user->notify(new Notifications\SpaceshipHasLaunched($spaceship));
Run Code Online (Sandbox Code Playgroud)

  • 这些是堆栈溢出的规则。当您回答问题时,您应该提供代码或对其进行解释,因此即使链接断开,您也可以通过仅阅读问题来解决问题。 (3认同)