dongyingming8970 2017-11-28 07:17
浏览 107
已采纳

命令“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

  • 写回答

1条回答 默认 最新

  • douti8321 2017-11-28 07:40
    关注

    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));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大