示例#1
0
 public function destroyAction()
 {
     return $this->respondTo(function ($format) {
         if (Request::isXhr()) {
             $resp = $this->jsonResponse(['success' => 'You are now logged out']);
         } else {
             $resp = $this->redirectTo('root');
         }
         return $resp->addCookie('dreamer', '', time(), '/');
     });
 }
示例#2
0
 public function currentUserAction()
 {
     if ($this->currentUser) {
         return $this->respondTo(function ($format) {
             if (Request::isXhr()) {
                 return $this->jsonResponse(['id' => $this->currentUser->id, 'username' => $this->currentUser->username]);
             }
         });
     } else {
         return $this->show404();
     }
 }
示例#3
0
 /**
  * Easily respond to different request types.
  */
 protected function respondTo(callable $callback)
 {
     // Is this an XMLHttpRequest? If not, use the request extension or fallback to HTML.
     $format = Request::isXhr() ? 'js' : Request::$properties->get('extension', 'html');
     return $callback($format);
 }