Ask Your Question
3

How can the redirect to the '/dashboard' route be achieved in a recently installed Laravel Sanctum API?

asked 2023-06-25 18:29:46 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-25 18:36:01 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-25 18:29:46 +0000

Seen: 14 times

Last updated: Jun 25 '23