Hello @kartik,
You can simply use the abort() helper. (Or App::abort())
public function handle($request, Closure $next) {
if (!Auth::check()) {
abort(403, 'Access denied');
}
return $next($request);
}
You can handle these exceptions inside App\Exceptions\Handler by overriding render() For example:
public function render($request, Exception $e)
{
if($e instanceof HttpException && $e->getStatusCode() == 403){
return new JsonResponse($e->getMessage(), 403);
}
return parent::render($request, $e);
}