Support the ongoing development of Laravel.io →
posted 1 year ago

Hi, this is my little problem: I've started my first proyect on laravel and one of the simplest function, logout, doesn't work: Into my controller AuthController.php I got this function:
public function logout(){ Auth::logout(); return response()->json(['message' => 'Ha salido correctamente']); } When I'm debugging, Auth::logout() throws next error: POST http://localhost:8000/api/logout [HTTP/1.1 500 Internal Server Error 30243ms] Could does it has to do the route in api.php with?:
Route::middleware(['auth:sanctum'])->group(function(){ Route::get('/user', [AuthController::class, 'user']); Route::post('/logout', [AuthController::class, 'logout']); }); thanks a lot for your attention and time!!

Last updated by @domalca 1 year ago.
0

Hi @domalca, what is the error message associated with the 500 error? You should have a record of that in the Laravel logs.

This post on Laracasts has a good discussion on the issue and I think you want something like Talinon's reply on there.

Last updated by @driesvints 1 year ago.
0
Solution

Many Thanks Musimana, it is solved just like this: Auth::guard('web')->logout();

0
Solution selected by @domalca

Sign in to participate in this thread!

Eventy

Your banner here too?

domalca domalca Joined 19 Mar 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.