Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To redirect to the '/dashboard' route in a Laravel Sanctum API, follow these steps:

  1. In your controller, after successful authentication, use the following code to redirect to the '/dashboard' route:
return redirect('/dashboard');
  1. In your web.php file, define the '/dashboard' route like this:
Route::get('/dashboard', 'DashboardController@index')->middleware('auth:sanctum');

Note: The 'auth:sanctum' middleware is used to ensure that only authenticated users can access the '/dashboard' route.

  1. In your DashboardController, define the index() method to return the view for the dashboard:
public function index()
{
   return view('dashboard');
}
  1. Create a view called 'dashboard.blade.php' in the views folder to display the dashboard.

That's it. Now, when a user successfully logs in, they will be redirected to the '/dashboard' route and see the corresponding dashboard view.