本文整理匯總了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);
}
}
示例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()]);
}
示例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);
}
示例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');
}
示例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);
}
}
示例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');
}
示例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);
}
}
示例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('/');
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}