laravel response json if not authorized

Solutions on MaxInterview for laravel response json if not authorized by the best coders in the world

showing results for - "laravel response json if not authorized"
Lautaro
10 Jan 2017
1>>> add this function in app/Exceptions/Handler.php
2
3use Illuminate\Auth\AuthenticationException;
4use Illuminate\Http\Request;
5use Illuminate\Http\Response;
6
7/**
8 * Convert an authentication exception into an unauthenticated response.
9 *
10 * @param  \Illuminate\Http\Request  $request
11 * @param  \Illuminate\Auth\AuthenticationException  $exception
12 * @return \Illuminate\Http\Response
13 */
14protected function unauthenticated($request, AuthenticationException $exception)
15{
16    return response()->json(['error' => 'Unauthenticated!'], 401);
17}