I have the following routes in my web.php file:
Route::get('/', 'PostsController@index')->name('home');
Route::get('/login', 'SessionsController@show');
SessionController class has a public constructor that uses Laravel's middleware to check if a user is a guest:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SessionsController extends Controller
{
public function __construct() {
$this->middleware('guest')->except(['destroy']);
public function create() {
// Validade form data
$this->validate(request(), [
'email' => 'required',
'password' => 'required'
]);
// Attempt to authenticate the user
if(! auth()->attempt(request(['email', 'password']))) {
return back()->withErrors([
'message' => 'Please check you credentials and try again'
]);
}
return redirect()->home();
}
public function show() {
return view('login.show');
}
public function destroy() {
auth()->logout();
return redirect()->home();
//return redirect()->route('home');
}
}
What happens is that when i'm logged in and i try to access /login
i'm being redirected to home
but i get a "sorry, page not found" in the browser. I understood that the middleware checks if i'm a guest when i try to login, if i'm not it should redirect me to the refereed page.
I checked php artisan route:list
and i can see that /
is assigned the name home
. I'm out of ideas now and i will appreciate any help.