public function enableCors()
 {
     $this->app->error(function (MethodNotAllowedHttpException $exception, $code) {
         if (\Request::getMethod() === "OPTIONS") {
             $headers = $exception->getHeaders();
             $allow = isset($headers['Allow']) ? $headers['Allow'] : '*';
             $headers = ['Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => $allow, 'Access-Control-Allow-Headers' => 'X-Requested-With, content-type'];
             return \Response::make('', 200, $headers);
         }
         return Serializers\Error::json(['code' => $code, 'message' => 'Method Not Allowed']);
     });
 }
Exemplo n.º 2
0
 public function filter()
 {
     if (!\Auth::check() or \Auth::guest()) {
         return Error::json(['code' => 401, 'message' => 'Unauthorized']);
     }
 }
Exemplo n.º 3
0
 public function error($options)
 {
     return Serializers\Error::json($options);
 }