當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::isJson方法代碼示例

本文整理匯總了PHP中Illuminate\Http\Request::isJson方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::isJson方法的具體用法?PHP Request::isJson怎麽用?PHP Request::isJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Http\Request的用法示例。


在下文中一共展示了Request::isJson方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: makeResponse

 protected function makeResponse(Request $request)
 {
     $message = $this->translator->get('c::auth.login-required');
     if ($request->ajax() || $request->isJson() || $request->wantsJson()) {
         return Response::json(['error' => $message], 403);
     } else {
         $url = $this->url->action('anlutro\\Core\\Web\\AuthController@login');
         $intended = $request->getMethod() == 'GET' ? $request->fullUrl() : ($request->header('referer') ?: '/');
         $this->session->put('url.intended', $intended);
         return $this->redirect->to($url)->with('error', $message);
     }
 }
開發者ID:anlutro,項目名稱:l4-core,代碼行數:12,代碼來源:AuthFilter.php

示例2: sendFailedLoginResponse

 /**
  * Get the failed login response instance.
  *
  * @param \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 protected function sendFailedLoginResponse(Request $request)
 {
     if ($request->wantsJson() || $request->isJson()) {
         return response($this->getFailedLoginMessage(), 401);
     }
     return redirect()->back()->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
開發者ID:Lidbetter,項目名稱:JWTokenGuard,代碼行數:13,代碼來源:AuthenticatesAndRegistersUsersAndJWT.php

示例3: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->isJson()) {
         return 'Acceso solo mediante json';
     }
     return $next($request);
 }
開發者ID:juanfe190,項目名稱:smartket,代碼行數:14,代碼來源:CheckApiMiddleware.php

示例4: index

 /**
  * @param Request $request
  *
  * @return View|JsonResponse
  */
 public function index(Request $request)
 {
     if ($request->isJson()) {
         return new JsonResponse(array_reverse($this->telegram->getUpdates()));
     }
     return $this->webUi->view('staff.telegram.index');
 }
開發者ID:hughgrigg,項目名稱:ching-shop,代碼行數:12,代碼來源:TelegramController.php

示例5: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->isJson()) {
         return $next($request);
     } else {
         return Json::response(['error' => true, 'message_info' => 'invalid input format, make sure your requests are in json'], Response::HTTP_BAD_REQUEST);
     }
 }
開發者ID:jamesddube,項目名稱:mps-server,代碼行數:15,代碼來源:JsonMiddleware.php

示例6: index

 public function index(Request $request)
 {
     $articles = $this->repository->allWithTerm($request->get('q'));
     if ($request->isJson()) {
         return response()->json($articles);
     }
     return $this->view('admin.index');
 }
開發者ID:rudenyl-eeweb,項目名稱:orocms-articles,代碼行數:8,代碼來源:AdminController.php

示例7: makeResponse

 protected function makeResponse(Request $request)
 {
     if ($request->ajax() || $request->isJson() || $request->wantsJson()) {
         return Response::json(['error' => $this->getErrorMessage()], 403);
     } else {
         $data = ['title' => $this->getErrorTitle(), 'text' => [$this->getErrorMessage()], 'homeUrl' => $this->getHomeUrl()];
         return Response::view('c::error', $data, 403);
     }
 }
開發者ID:anlutro,項目名稱:l4-core,代碼行數:9,代碼來源:AccessFilter.php

示例8: logIn

 public function logIn(Request $request)
 {
     Log::debug("JWTAuthController.logIn.begin");
     try {
         $username = "";
         if (!$request->isJson()) {
             $credentials = ["username" => $request->get("username"), "password" => $request->get("inputPassword")];
         } else {
             Log::debug("JWTAuthController.logIn:" . print_r($request->json()->all(), true));
             $credentials = $request->json()->all();
         }
         Log::debug("JWTAuthController.logIn.password:" . $credentials['password']);
         $user = DB::table('users')->where('username', $credentials['username'])->first();
         Log::debug("JWTAuthController.user:" . print_r($user, true));
         if ($user == null || !Hash::check($credentials['password'], $user->password)) {
             if ($user == null) {
                 Log::debug("JWTAuthController.logIn.User Not Found");
             } else {
                 Log::debug("JWTAuthController.logIn.Password Error");
             }
             if ($request->isJson()) {
                 return response()->json(false, 401);
             } else {
                 return view("login", ["errorMessage" => "Wrong User Or Password"]);
             }
         }
         $token = JWTAuth::fromUser($user);
         DragoCookie::setCookie($token, 10, false);
     } catch (Exception $e) {
         Log::error("JWTAuthController.logIn.exception:" . $e->getMessage());
         if ($request->isJson()) {
             return response()->json($e->getMessage());
         } else {
             return view("login", ["errorMessage" => "Something gone wrong. Please Retry"]);
         }
     }
     Log::debug("JWTAuthController.logIn.end");
     if ($request->isJson()) {
         return response()->json(["jwt" => $token]);
     } else {
         return redirect('/');
     }
 }
開發者ID:edragonetti,項目名稱:empa-Assign,代碼行數:43,代碼來源:JWTAuthController.php

示例9: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->isJson()) {
         if (in_array($request->getMethod(), self::PARSED_METHODS)) {
             if (strlen($request->getContent()) != 0) {
                 $request->merge(json_decode($request->getContent(), true));
             }
         }
     }
     return $next($request);
 }
開發者ID:aninditkarmakar,項目名稱:salmu-desi,代碼行數:18,代碼來源:JsonRequestMergerMiddleware.php

示例10: renderExceptionWithWhoops

 /**
  * @param Request $request
  * @param Exception $exception
  * @return Response
  * @throws \InvalidArgumentException
  */
 protected function renderExceptionWithWhoops(Request $request, Exception $exception)
 {
     $whoops = new Whoops();
     if ($request->isJson() || $request->wantsJson()) {
         $whoops->pushHandler(new JsonResponseHandler());
     } else {
         $whoops->pushHandler(new PrettyPageHandler());
     }
     $code = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
     $headers = $exception instanceof HttpException ? $exception->getHeaders() : [];
     return new Response($whoops->handleException($exception), $code, $headers);
 }
開發者ID:vlsoprun,項目名稱:store,代碼行數:18,代碼來源:Handler.php

示例11: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($request->isJson()) {
         if ($e instanceof ApiParcelException) {
             return (new ApiParcel())->addParcelException($e);
         } else {
             return (new ApiParcel())->addGenericException($e);
         }
     } else {
         return parent::render($request, $e);
     }
 }
開發者ID:schleumer,項目名稱:php-mercurio,代碼行數:19,代碼來源:Handler.php

示例12: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     // Catch specific Exceptions and return a custom error message
     if ($request->isJson()) {
         if ($e instanceof ModelNotFoundException) {
             return response()->json(['error' => 'Resource could not be found.'], 404);
         }
     }
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     return parent::render($request, $e);
 }
開發者ID:MyGrades,項目名稱:mygrades-server,代碼行數:20,代碼來源:Handler.php

示例13: onBefore

 /**
  * Check the Request before running it through the router.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response|null
  */
 public function onBefore($request)
 {
     $keys = $this->app['config']->get('api-inspector');
     App::bind('Pusher', function ($app) {
         $keys = $this->app['config']->get('api-inspector');
         return new \Pusher($keys['public'], $keys['secret'], $keys['app_id']);
     });
     if ($keys['active'] == false) {
         return;
     }
     App::make('Pusher')->trigger('apiChannel', 'apiCall', ['method' => $request->method(), 'root' => $request->root(), 'url' => $request->url(), 'path' => $request->path(), 'ajax' => $request->ajax(), 'ip' => $request->ip(), 'input' => $request->all(), 'is-json' => $request->isJson(), 'format' => $request->format(), 'session' => json_encode($request->session()), 'header' => $request->header(), 'input-json' => json_encode($request->json()), 'wants-json' => $request->wantsJson()]);
     return;
 }
開發者ID:hvent90,項目名稱:api-inspector,代碼行數:19,代碼來源:ApiInspectorServiceProvider.php

示例14: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if (config('app.debug')) {
         if ($request->isJson() || $request->isXmlHttpRequest()) {
             return response(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
         }
         return $this->renderExceptionWithWhoops($e);
     }
     return parent::render($request, $e);
 }
開發者ID:RoryStolzenberg,項目名稱:spacexstats,代碼行數:20,代碼來源:Handler.php

示例15: render

 /**
  *      * Render an exception into an HTTP response.
  *           *
  *                * @param  \Illuminate\Http\Request $request
  *                     * @param  \Exception $e
  *                          * @return \Illuminate\Http\Response
  *                               */
 public function render($request, Exception $e)
 {
     if ($this->isHttpException($e)) {
         return $this->renderHttpException($e);
     }
     if ($request->isJson()) {
         return Response::exception($e);
     }
     if (config('app.debug')) {
         return $this->renderExceptionWithWhoops($e);
     }
     return parent::render($request, $e);
 }
開發者ID:imjerrybao,項目名稱:PushApp,代碼行數:20,代碼來源:Handler.php


注:本文中的Illuminate\Http\Request::isJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。