/**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     if (!Auth::guest()) {
         $n = Notification::byUser(Auth::user())->unread()->get();
         $view->with('notifications', ['count' => $n->count(), 'notifications' => $n]);
     }
 }
 /**
  * Read a notification
  * @param $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function read($id)
 {
     $notification = Notification::findOrFail($id);
     if ($notification->user_id != Auth::user()->id) {
         abort(403);
     }
     if (empty($notification->readed_at)) {
         $notification->readed_at = Carbon::now();
         $notification->save();
         event(new NotificationWasReaded($notification));
     }
     event(new NotificationWasOpened($notification));
     if (!empty($notification->link)) {
         return redirect()->to($notification->link);
     }
     return redirect()->route('notifications');
 }
 public function handle($command)
 {
     $notification = Notification::create((array) $command);
     event(new NotificationWasSent($notification));
     return $notification;
 }