<img height="1" width="1" style="display:none;" alt="" src="https://ct.pinterest.com/v3/?event=init&amp;tid=2612994575055&amp;pd[em]=<hashed_email_address>&amp;noscript=1">
Skip to content
    Oct 2, 2023 3:58:56 PM< 1 min read

    Laravel return json not authentication

    Laravel return json not authentication

    Open app\Http\Middleware\Authenticate.php

    protected function redirectTo($request)
    {
        if( $request->is('api/*')){
            abort(response()->json(['status' => 401, 'message' => 'Unauthorized'], 401));
        }
    
        if (! $request->expectsJson()) {
            return route('login');
        }else{
            abort(response()->json(['status' => 401, 'message' => 'Unauthorized'], 401));
        }
    }

    click for more Laravel codes read about laravel authentication

    COMMENTS

    RELATED ARTICLES