当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::wantsJson方法代码示例

本文整理汇总了PHP中Illuminate\Http\Request::wantsJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::wantsJson方法的具体用法?PHP Request::wantsJson怎么用?PHP Request::wantsJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Http\Request的用法示例。


在下文中一共展示了Request::wantsJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postChangePassword

 public function postChangePassword()
 {
     $newPassword = $this->request->input('password');
     $token = $this->request->input('spToken');
     $validator = $this->loginValidator();
     if ($validator->fails()) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError('Validation Failed', 400, ['validatonErrors' => $validator->errors()]);
         }
         return redirect()->to(config('stormpath.web.changePassword.uri') . '?spToken=' . $token)->withErrors($validator);
     }
     $application = app('stormpath.application');
     try {
         $application->resetPassword($token, $newPassword);
         // the password has been changed. Time to fire the
         // `UserHasResetPassword` event
         //
         Event::fire(new UserHasResetPassword());
         if ($this->request->wantsJson()) {
             return $this->respondOk();
         }
         return redirect()->to(config('stormpath.web.changePassword.nextUri'));
     } catch (\Stormpath\Resource\ResourceError $re) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError($re->getMessage(), $re->getStatus());
         }
         return redirect()->to(config('stormpath.web.changePassword.errorUri'))->withErrors(['errors' => [$re->getMessage()]]);
     }
 }
开发者ID:stormpath,项目名称:stormpath-laravel,代码行数:29,代码来源:ChangePasswordController.php

示例2: 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)
 {
     // 404 page when a model is not found
     if ($e instanceof ModelNotFoundException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado'], 404);
         }
         return response()->view('errors.404', [], 404);
     }
     if ($this->isHttpException($e)) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado!'], 404);
         }
         return $this->renderHttpException($e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             if ($request->ajax() || $request->wantsJson()) {
                 return response()->json(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
             }
             return response()->view('errors.500', [], 500);
         }
         return parent::render($request, $e);
     }
 }
开发者ID:Nemeziz,项目名称:inegi,代码行数:32,代码来源:Handler.php

示例3: postRegister

 public function postRegister()
 {
     $validator = $this->registerValidator();
     if ($validator->fails()) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError('Validation Failed', 400, ['validatonErrors' => $validator->errors()]);
         }
         return redirect()->to(config('stormpath.web.register.uri'))->withErrors($validator)->withInput();
     }
     try {
         $registerFields = $this->setRegisterFields();
         $account = \Stormpath\Resource\Account::instantiate($registerFields);
         $application = app('stormpath.application');
         $account = $application->createAccount($account);
         if ($this->request->wantsJson()) {
             return $this->respondWithAccount($account);
         }
         if (config('stormpath.web.verifyEmail.enabled') == true) {
             return redirect()->route('stormpath.login', ['status' => 'unverified']);
         }
         if (config('stormpath.web.register.autoAuthorize') == false) {
             return redirect()->route('stormpath.login', ['status' => 'created']);
         }
         $login = isset($registerFields['username']) ? $registerFields['username'] : null;
         $login = isset($registerFields['email']) ? $registerFields['email'] : $login;
         $result = $this->authenticate($login, $registerFields['password']);
         return redirect()->to(config('stormpath.web.register.nextUri'))->withCookies([config('stormpath.web.accessTokenCookie.name') => cookie(config('stormpath.web.accessTokenCookie.name'), $result->getAccessTokenString(), $result->getExpiresIn(), config('stormpath.web.accessTokenCookie.path'), config('stormpath.web.accessTokenCookie.domain'), config('stormpath.web.accessTokenCookie.secure'), config('stormpath.web.accessTokenCookie.httpOnly')), config('stormpath.web.refreshTokenCookie.name') => cookie(config('stormpath.web.refreshTokenCookie.name'), $result->getRefreshTokenString(), $result->getExpiresIn(), config('stormpath.web.refreshTokenCookie.path'), config('stormpath.web.refreshTokenCookie.domain'), config('stormpath.web.refreshTokenCookie.secure'), config('stormpath.web.refreshTokenCookie.httpOnly'))]);
     } catch (\Stormpath\Resource\ResourceError $re) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError($re->getMessage(), $re->getStatus());
         }
         return redirect()->to(config('stormpath.web.register.uri'))->withErrors(['errors' => [$re->getMessage()]])->withInput();
     }
 }
开发者ID:Kryten0807,项目名称:stormpath-laravel,代码行数:34,代码来源:RegisterController.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $role, $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('login');
         }
     }
     if (user($guard)->new && config('user.verify_email')) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect('verify');
         }
     }
     if (!user($guard)->active && config('user.verify_email')) {
         throw new InvalidAccountException('Account is not active.');
     }
     $roles = explode('|', $role);
     if (!user($guard)->hasRoles($roles)) {
         throw new RolesDeniedException($roles);
     }
     return $next($request);
 }
开发者ID:LavaLite,项目名称:framework,代码行数:33,代码来源:VerifyRole.php

示例5: 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) {
         return redirect('/');
     }
     if ($e instanceof MethodNotAllowedHttpException) {
         return redirect('/');
     }
     if ($e instanceof NotFoundHttpException) {
         return response(view('errors.404'), 404);
     }
     if ($e instanceof InvalidConfirmationCodeException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect('/');
     }
     if ($e instanceof UserNotOwnerOfProjectException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project'));
     }
     if ($e instanceof ProjectCompletedException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project'));
     }
     if ($e instanceof UserRequiresAuthenticationException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['login' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.login')]);
         } else {
             Session::flash('flash_message', $e->getMessage());
             return redirect('/');
         }
     }
     if ($e instanceof UserHasIncompleteProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['incomplete' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.incomplete')]);
         }
     }
     if ($e instanceof UserAlreadyHasSubmittedProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['pendingProject' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.pending-project')]);
         }
     }
     if ($e instanceof UserHasCurrentLiveProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['liveProject' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.live-project')]);
         }
     }
     if ($e instanceof ProjectNameAlreadyTakenException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['duplicateName' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.duplicate-name')]);
         }
     }
     return parent::render($request, $e);
 }
开发者ID:andreikainer,项目名称:kuj_abol,代码行数:60,代码来源:Handler.php

示例6: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->ajax() && !$request->wantsJson()) {
         $response = $next($request);
         $content = $response->getContent();
         $pos = strripos($content, '</body>');
         if (false !== $pos) {
             $components = config('components');
             $newMatches = true;
             $matchedComponents = [];
             while ($newMatches == true) {
                 $renderedContent = '';
                 $newEls = 0;
                 //loop registered components and add templates as needed.
                 foreach ($components as $id => $component) {
                     if (str_contains($content, '<' . $id) && !in_array($id, $matchedComponents)) {
                         $newEls++;
                         $matchedComponents[] = $id;
                         $componentView = view($component['view']);
                         $renderedContent .= $componentView;
                         $this->systemJs->import()->item($component['js']);
                     }
                 }
                 $content = substr($content, 0, $pos) . $renderedContent . substr($content, $pos);
                 if ($newEls === 0) {
                     $newMatches = false;
                 }
             }
             $response->setContent($content);
         }
         return $response;
     }
     return $next($request);
 }
开发者ID:fluentkit,项目名称:fluentkit,代码行数:42,代码来源:AddComponents.php

示例7: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->wantsJson()) {
         return $next($request);
     }
     abort(401);
 }
开发者ID:rosemalejohn,项目名称:dnsc-hris,代码行数:14,代码来源:APIMiddleware.php

示例8: 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);
     }
     /**
      * Response Exception as Json
      *
      */
     if ($request->wantsJson()) {
         $error = new \stdclass();
         $error->error = true;
         if ($e instanceof NotFoundHttpException) {
             $error->code = $e->getStatusCode();
         } else {
             $error->code = $e->getCode();
         }
         if ($error->code == 0) {
             $error->code = 400;
         }
         if ($e instanceof ValidatorException) {
             $error->message = $e->getMessageBag();
         } else {
             $error->message = $e->getMessage();
             if (\App::environment('local')) {
                 $error->file = $e->getFile();
                 $error->line = $e->getLine();
             }
         }
         return response()->json($error, $error->code);
     }
     return parent::render($request, $e);
 }
开发者ID:adrianodrix,项目名称:codedelivery.dev,代码行数:40,代码来源:Handler.php

示例9: 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->wantsJson()) {
         // Define the response
         $response = ['errors' => 'Sorry, something went wrong.'];
         // If the app is in debug mode
         if (config('app.debug')) {
             // Add the exception class name, message and stack trace to response
             $response['exception'] = get_class($e);
             // Reflection might be better here
             $response['message'] = $e->getMessage();
             $response['trace'] = $e->getTrace();
         }
         // Default response of 400
         $status = 400;
         // If this exception is an instance of HttpException
         if ($this->isHttpException($e)) {
             // Grab the HTTP status code from the Exception
             $status = $e->getStatusCode();
         }
         // Return a JSON response with the response array and status code
         return response()->json($response, $status);
     }
     // Default to the parent class' implementation of handler
     return parent::render($request, $e);
 }
开发者ID:tdtrung17693,项目名称:Rabbitnote,代码行数:33,代码来源:Handler.php

示例10: 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->wantsJson()) {
         return response(['success' => false, 'message' => $e->getMessage()], 404);
     }
     return parent::render($request, $e);
 }
开发者ID:bossrabbit,项目名称:custom-directives-and-asynchronous-forms,代码行数:14,代码来源:Handler.php

示例11: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if ($request->ajax() || $request->wantsJson()) {
         return $next($request);
     }
     return new Response('', 400);
 }
开发者ID:oldtimeguitarguy,项目名称:laravel-ajax-middleware,代码行数:14,代码来源:AjaxMiddleware.php

示例12: deleteKey

 /**
  *	delete key registered (Only this seller)
  *	@param	$id 	int|string 	id the virtual product
  *	@param	$res 	Request 	object to validate the type of request, action
  *	@return	json
  */
 public function deleteKey($id, Request $res)
 {
     if (!$res->wantsJson()) {
         return redirect()->back();
     }
     $VirtualProduct = VirtualProduct::find($id);
     if (!count($VirtualProduct->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available')]);
     }
     $product = Product::find($VirtualProduct->product_id);
     if (!count($product->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available')]);
     }
     if ($product->user_id != \Auth::id()) {
         return json_encode(['message' => trans('globals.not_access')]);
     }
     $VirtualProductOrder = VirtualProductOrder::where('virtual_product_id', $VirtualProduct->id)->get();
     if (count($VirtualProductOrder->toArray()) > 0) {
         return json_encode(['message' => trans('product.virtualProductsController_controller.key_been_sold')]);
     }
     $VirtualProduct->status = 'cancelled';
     $VirtualProduct->save();
     $stock = count(VirtualProduct::where('product_id', $product->id)->where('status', 'open')->get()->toArray());
     $product->stock = $stock;
     if ($stock == 0) {
         $product->status = 0;
     }
     $product->save();
     return json_encode(['success' => trans('product.controller.saved_successfully')]);
 }
开发者ID:masterpowers,项目名称:antVel,代码行数:36,代码来源:VirtualProductsController.php

示例13: handle

 /**
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function handle($request, Closure $next)
 {
     if (!$request->ajax() && !$request->wantsJson()) {
         abort(415);
     }
     return $next($request);
 }
开发者ID:kevinsimard,项目名称:laravel-app,代码行数:14,代码来源:AssertJsonRequest.php

示例14: tokensMatch

 /**
  * Determine if the session and input CSRF tokens match when the request is not a json.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return bool
  */
 protected function tokensMatch($request)
 {
     if ($request->wantsJson()) {
         return true;
     }
     return parent::tokensMatch($request);
 }
开发者ID:CENTRUM21,项目名称:laravel-apz,代码行数:13,代码来源:VerifyCsrfToken.php

示例15: edit

 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Request $request, $id)
 {
     if ($request->wantsJson() || $request->ajax()) {
         throw new \Exception('Editing is not supported by AJAX');
     }
     return view('project.edit')->with(['project' => Project::find($id)]);
 }
开发者ID:jayaregalinada,项目名称:portfolio-legacy,代码行数:13,代码来源:ProjectController.php


注:本文中的Illuminate\Http\Request::wantsJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。