2017-09-24 1 views
4

실시간 알림을 만드는 중입니다.이 이상한 오류가 발생했습니다. 내 모델에서 SendNotificationData (리스너 없음)이라는 이벤트를 트리거하는 부트 방법이 있습니다. 새로운 알림이있을 때 처리합니다.Laravel - 404 오류를 일으키는 이벤트

시험 컨트롤러

<?php 

namespace App\Http\Controllers\Notification; 

use App\Http\Controllers\Controller; 
use Illuminate\Http\Request; 

use App\Http\Requests; 
use App\Models\Notification; 

class NotificationController extends Controller 
{ 
    /** 
    * Trigger event to display notifications. This displays 404 error page 
    * 
    * @return none 
    */ 
    public function displayNotification() 
    { 
     $notification = new Notification(); 
     $notification->EmployeeID = "EMP-00001"; 
     $notification->NotificationText = "There is a new notification"; 
     $notification->NotificationStatus = "unread"; 
     $notification->NotificationType = "trial"; 
     $notification->save(); 
    } 
} 

알림 모델 부팅 방법 :

namespace App\Events; 

use App\Events\Event; 
use Illuminate\Queue\SerializesModels; 
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; 

class SendNotificationData extends Event implements ShouldBroadcast 
{ 
    use SerializesModels; 

    public $new_notification_data; 

    /** 
    * Create a new event instance. 
    * 
    * @param $notification_data 
    * @return void 
    */ 
    public function __construct($new_notification_data) 
    { 
     $this->new_notification_data = $new_notification_data; 
    } 

    /** 
    * Get the channels the event should be broadcast on. 
    * 
    * @return array 
    */ 
    public function broadcastOn() 
    { 
     return ['new-notification']; 
    } 

    /** 
    * Customize event name. 
    * 
    * @return array 
    */ 
    public function broadcastAs() 
    { 
     return 'private-send-new-notification'; 
    } 
} 

0,123,787 Javascript에 : 이것은 내 SendNotificationData 이벤트가

/** 
* Handle booting of model. 
* 
* @var string 
*/ 
public static function boot() 
{ 
    static::created(function ($data) { 
     event(new SendNotificationData($data)); 
    }); 

    parent::boot(); 
} 

입니다

이제 컨트롤러에서 임의의 알림을 추가하려고하면 이벤트가 발생합니다. 그러나 404 오류 페이지가 나에게 표시됩니다. ShouldBroadcast 인터페이스를 제거하거나 생성자의 내용을 제거하면 더 이상 오류가 표시되지 않습니다. 내 다른 이벤트가 정상적으로 작동 할 때 이러한 오류를 일으킬 수있는 것이 혼란 스럽습니다. 나는 뭔가를 놓친 것일 수 있으므로 나를 안내 해주십시오.

+0

컨트롤러 코드도 제공 할 수 있습니까? – apokryfos

+0

평가판 컨트롤러 코드를 추가했습니다. –

+0

실제로 해당 컨트롤러 작업을 방문하기 위해 경로가 올바르게 설정 되었습니까? (함수의'dd (something)'은 그것이 맞았는지 아닌지 알려줄 수 있습니다). 또한 채널에서들을 때 사용할 JS를 공유 할 수 있습니까? – apokryfos

답변

1

나는 그것을 믿을 수 없다가,이 모델의 $incrementing 변수에 의해 야기 된이 false 대신 true로 설정됩니다. laravel 만 올바른 오류 스택 추적을 표시합니다.

관련 문제