/**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('messages', function ($id) {
         return \App\Messages::findOrFail($id);
     });
     $router->bind('tweets', function ($id) {
         return \App\Tweet::findOrFail($id);
     });
     $router->bind('users', function ($id) {
         return \App\User::findOrFail($id);
     });
     parent::boot($router);
 }
 public function viewMessage(Request $request, $id)
 {
     $user = User::findOrFail(Auth::user()['id']);
     // Check if user owns this message
     $message = Messages::findOrFail($id);
     if ($user->id != $message->recipient) {
         $request->session()->flash('error', 'You are not allowed to perform that action.');
         return redirect('/messages');
     }
     // Mark as read
     $message->unread = false;
     $message->save();
     // Sender info
     $sender = User::findOrFail($message->sender);
     return $this->view('home.message-view', ['message' => $message, 'sender' => $sender, 'attachments' => explode('|', $message->attachments)]);
 }