2017-11-28 8 views
0

루멘에서 푸시 알림 응용 프로그램을 개발하는 과정에서 알림을 작성하려면 php artisan 명령을 실행해야합니다. php artisanmake:notification (php artisan make:notification) 명령을 실행할 수 없습니다. 다음과 같은 오류가 발생합니다."make : notification"명령이 정의되지 않았습니다. | 루멘 5.5

[Symfony\Component\Console\Exception\CommandNotFoundException] 

Command "make:notification" is not defined.

Did you mean one of these? 
     make:migration 
     make:seeder 

이 문제를 해결하는 데 도움을주십시오. 감사합니다.

+0

루멘에 해당 기능이 있는지 확실하지 않습니다 ... 루멘은 API 프레임 워크입니다. Laravel에서 버전 5.3 이후에 함수가 있다고 생각합니다. – lewis4u

+0

버전 5.5를 사용 중입니다 – CoolCK

+0

Laravel 또는 Lumen ??? – lewis4u

답변

3

명령 php artisan make:notification NameOfNotification은 루멘에 존재하지 않습니다.

해당 패키지를 가져와야합니다.

출처 :이의 필수 의존성 경우 어쩌면

composer require illuminate/notifications 

당신이, 내가 100 % 아니에요 require illuminate/support됩니다 https://stevethomas.com.au/php/using-laravel-notifications-in-lumen.html


는 첫 번째 단계는 켜 집/알림 패키지를 필요로한다 알림. 오류가 발생하면 이것이 원인 일 수 있습니다.

다음, 부트 스트랩에서 서비스 공급자를 등록/app.php

$app->register(\Illuminate\Notifications\NotificationServiceProvider::class); 

// optional: register the Facade 
$app->withFacades(true, [ 
    'Illuminate\Support\Facades\Notification' => 'Notification', 
]); 

중 모델 당신이 좋아하는 신고해야할 특성을 추가, 사용자는 명백한 하나가 될 것입니다 :

<?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)); 
+0

거의 같은 기사 붙여 넣기 : D. 어쨌든 나는 upvoted :) – CoolCK

+1

그 스택 오버플로 규칙이 있습니다. 대답을 할 때 코드를 제공하거나 설명해야하므로 링크가 끊어져도 질문 만 읽으면 문제를 해결할 수 있습니다. – lewis4u

+0

도움을 주셔서 감사합니다 :) – CoolCK