Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

luxaloli's avatar

Laravel showing API response instead of web view

Hello, I am working on a Laravel web app that has a small quirk that happens from time to time.

When logging into the app instead of going to the /dashboard route that is the home page sometimes it redirects to the /api/checkin/{id} endpoint, that is one of the api endpoints the /dashboard page uses.

it doesn't happen always is just from time to time, and very annoying to users.

Any Idea on what may be happening?

0 likes
2 replies
luxaloli's avatar

@tisuchi thanks this is the login controller

<?php

namespace App\Http\Controllers\Frontend\Auth;

use App\Http\Controllers\Controller;
use App\Services\Access\Traits\AuthenticatesUsers;
use App\Services\Access\Traits\UseSocialite;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers, UseSocialite;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/dashboard';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
        $this->middleware('auth', ['only' => 'logout']);
    }
}

and this is the frontend controller where it redirects to the dashboard

<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;

/**
 * Class FrontendController
 * @package App\Http\Controllers
 */
class FrontendController extends Controller
{
    /**
     * @return \Illuminate\View\View
     */
    public function index()
    {
      if(auth()->user()){
        return redirect()->route('frontend.user.dashboard');
      }
      else
      {
        return view('frontend.auth.login');
      }
    }
}

this is the dashboard route code

Route::group(['middleware' => 'auth'], function () {
    Route::group(['namespace' => 'User'], function() {
        Route::get('dashboard', 'DashboardController@index')->name('frontend.user.dashboard');
		...
	});
});

on the dashboard controller

<?php

namespace App\Http\Controllers\Frontend\AppName;

use App\Http\Controllers\Controller;
use App\Models\Access\User\User;
use App\Models\Access\User\Locations;
use App\Models\Access\User\Category;
use App\Models\Access\User\CheckinReporting;
use App\Models\Access\User\ClosedTicket;

use Illuminate\Http\Request;
use DB;
use DateTimeZone;
use DateTime;

/**
 * Class FrontendController
 * @package App\Http\Controllers
 */
class DashboardController extends Controller
{

    public function index()
    {
     //......a bunch of data fetching

        return view('frontend.appName.dashboard')
            ->with('userEmail', $userEmail)
            ->with('accessToken', $accessToken)
            ->withCategories($categories)
            ->withStaff($staff)
            ->withLocationsList($locations_list);
    }
}

in the times that redirects to an api endpoint I get a 302 code on login

Please or to participate in this conversation.