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


PHP Request::expectsJson方法代码示例

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


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

示例1: convertValidationExceptionToResponse

 /**
  * Create a response object from the given validation exception.
  *
  * @param  \Illuminate\Validation\ValidationException  $e
  * @param  \Illuminate\Http\Request  $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function convertValidationExceptionToResponse(ValidationException $e, $request)
 {
     if ($e->response) {
         return $e->response;
     }
     $errors = $e->validator->errors()->getMessages();
     if ($request->expectsJson()) {
         return response()->json($errors, 422);
     }
     return redirect()->back()->withInput($request->input())->withErrors($errors);
 }
开发者ID:uxweb,项目名称:framework,代码行数:18,代码来源:Handler.php

示例2: unauthenticated

 /**
  * Convert an authentication exception into an unauthenticated response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Auth\AuthenticationException  $exception
  * @return \Illuminate\Http\Response
  */
 protected function unauthenticated($request, AuthenticationException $exception)
 {
     if ($request->expectsJson()) {
         return response()->json(['error' => 'Unauthenticated.'], 401);
     }
     return redirect()->guest('login');
 }
开发者ID:hownowbrowncow,项目名称:website,代码行数:14,代码来源:Handler.php

示例3: expectsJson

 /**
  * Determine if the current request probably expects a JSON response.
  *
  * @return bool
  * @static
  */
 public static function expectsJson()
 {
     return \Illuminate\Http\Request::expectsJson();
 }
开发者ID:Dimimo,项目名称:Booklet,代码行数:10,代码来源:_ide_helper.php

示例4: unauthenticated

 /**
  * Convert an authentication exception into an unauthenticated response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Auth\AuthenticationException  $exception
  * @return \Illuminate\Http\Response
  */
 protected function unauthenticated($request, AuthenticationException $exception)
 {
     if ($request->expectsJson() || $this->isApiRoute($request)) {
         return response()->json(['error' => $exception->getMessage()], 401);
     }
     return redirect()->guest('login');
 }
开发者ID:jadjoubran,项目名称:laravel5-angular-material-starter,代码行数:14,代码来源:Handler.php

示例5: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     # Skip API related requests
     if ($request->expectsJson()) {
         return $next($request);
     }
     return parent::handle($request, $next);
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:16,代码来源:VerifyCsrfToken.php

示例6: unauthenticated

 /**
  * Convert an authentication exception into an unauthenticated response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Auth\AuthenticationException  $e
  * @return \Illuminate\Http\Response
  */
 protected function unauthenticated($request, AuthenticationException $e)
 {
     if ($request->expectsJson()) {
         return response()->json(['error' => 'Unauthenticated.'], 401);
     } else {
         return view('canvas::auth.login');
     }
 }
开发者ID:austintoddj,项目名称:canvas,代码行数:15,代码来源:Handler.php

示例7: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return \Closure|\Illuminate\Http\RedirectResponse
  * @throws \App\Exceptions\Users\UserAlreadyLoggedInException
  */
 public function handle(Request $request, \Closure $next)
 {
     if (app('auth.driver')->check()) {
         if ($request->expectsJson()) {
             throw new UserAlreadyLoggedInException();
         }
         return redirect('/');
     }
     return $next($request);
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:19,代码来源:RedirectIfAuthenticated.php

示例8: handle

 /**
  * Handle an incoming request.
  *
  * @param  Request  $request
  * @param  \Closure $next
  *
  * @return mixed
  */
 public function handle(Request $request, \Closure $next)
 {
     if (app('auth.driver')->guest()) {
         if ($request->expectsJson()) {
             throw new UnauthorizedHttpException('Unauthorized');
         } else {
             return redirect()->guest(route(app('translator')->getLocale() . '.login'));
         }
     }
     return $next($request);
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:19,代码来源:Authenticate.php

示例9: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $exception
  * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse|null
  */
 public function render($request, Exception $exception)
 {
     if ($exception instanceof RejectedInputException) {
         $errors[$exception->getAttribute()] = 'There was a problem with this field.';
         if ($request->expectsJson()) {
             return response()->json($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
         }
         return redirect()->back()->withInput($request->input())->withErrors($errors);
     }
     return null;
 }
开发者ID:artissant,项目名称:laravel,代码行数:18,代码来源:HandleRejectedInputException.php

示例10: register

 /**
  * Store a newly created user.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \App\Exceptions\Common\ValidationException
  */
 public function register(Request $request)
 {
     $validator = app('validator')->make($request->all(), ['name' => 'sometimes|required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:' . config('auth.passwords.users.min_length')]);
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     $user = new User();
     $request->has('name') && ($user->name = $request->input('name'));
     $user->email = $request->input('email');
     $user->password = app('hash')->make($request->input('password'));
     $user->save() && event(new Registered($user));
     app('auth.driver')->login($user);
     return $request->expectsJson() ? response()->json($user)->setStatusCode(IlluminateResponse::HTTP_CREATED) : redirect($this->redirectPath());
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:22,代码来源:RegisterController.php

示例11: activate

 /**
  * Activate an account [Web only].
  *
  * @param \Illuminate\Http\Request $request
  * @param string|null              $token
  *
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  * @throws \App\Exceptions\Common\ValidationException
  */
 public function activate(Request $request, $token = null)
 {
     $data = !is_null($token) ? ['token' => $token] : $request->all();
     $validator = app('validator')->make($data, ['token' => 'required|string']);
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     $activation = UserActivation::whereCode($data['token'])->first();
     if (!$activation) {
         throw new TokenNotValidException();
     }
     /** @var \App\Models\User $user */
     $user = User::findOrFail($activation->user_id);
     $this->complete($user, $data['token']);
     return $request->expectsJson() ? response()->json(['message' => 'Activated']) : redirect($this->redirectPath())->with('message', 'Activation successful');
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:25,代码来源:ActivateController.php

示例12: buildFailedValidationResponse

 /**
  * @param \Illuminate\Http\Request $request
  * @param array                    $errors
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function buildFailedValidationResponse(Request $request, array $errors)
 {
     if ($request->expectsJson()) {
         return new JsonResponse($errors, 422);
     }
     return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
 }
开发者ID:notadd,项目名称:framework,代码行数:13,代码来源:ValidatesRequests.php

示例13: logout

 /**
  * Log the user out of the application.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
  */
 public function logout(Request $request)
 {
     $user = app('auth.driver')->user();
     app('auth.driver')->logout();
     $request->session()->flush();
     $request->session()->regenerate();
     app('events')->fire(new LoggedOut($user));
     if ($request->expectsJson()) {
         return response()->json([]);
     }
     return redirect('/');
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:19,代码来源:LoginController.php

示例14: resetPassword

 /**
  * Reset the password through password-reset-token and email provided.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  * @throws \App\Exceptions\Common\ValidationException
  */
 public function resetPassword(Request $request)
 {
     $validator = app('validator')->make($request->all(), ['token' => 'required|string', 'email' => 'required|email|max:255', 'password' => 'required|confirmed|min:' . app('config')->get('auth.passwords.users.min_length')]);
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     $credentials = $request->only('email', 'password', 'password_confirmation', 'token');
     $passwordBroker = app('auth.password.broker');
     $response = $passwordBroker->reset($credentials, function (User $user, $password) {
         $user->password = app('hash')->make($password);
         $user->save();
         app('auth.driver')->login($user);
     });
     switch ($response) {
         case $passwordBroker::INVALID_USER:
             throw new ModelNotFoundException(trans($response));
             break;
         case $passwordBroker::INVALID_TOKEN:
             throw new TokenNotValidException(trans($response));
             break;
     }
     event(new ResetPassword(app('auth.driver')->user()));
     if ($request->expectsJson()) {
         return response()->json(['message' => trans('passwords.reset')]);
     }
     return redirect($this->redirectPath())->with('message', trans('passwords.reset'));
 }
开发者ID:audithsoftworks,项目名称:basis,代码行数:35,代码来源:PasswordController.php


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