Ad

Laravel Base URL Redirecting To /home For No Reason

I'm learning laravel and I have a problem with my base url which is http://localhost/.

It keeps redirecting to http://localhost/home which is the base authentication route and since im not logged in, it redirects me to http://localhost/login.

I want http://localhost/ to redirect to http://localhost/blog/posts as it should.

I'm doing this because in the future the base url will redirect to another page. Until then, I want to display the blog posts.

web.php

Route::get('/', [
    'as' => 'index',
    'uses' => '[email protected]',
]);

Route::get('/blog/posts', [
    'as' => 'blog',
    'uses' => '[email protected]'
]);

Auth::routes();

Route::get('/home', [
    'as' => 'home',
    'uses' => '[email protected]'
]);

HomeController.php

public function home()
{
    return view('home');
}

public function index()
{
    return view('blog');
}

I hope I was clear enough, i'd be glad to give more info if needed.

Problem solved:

Comment or remove $this->middleware('auth'); in HomeController.php and add it in the route:

Route::get('/home', [
    'as' => 'home',
    'uses' => '[email protected]'
])->middleware('auth');
Ad

Answer

Check that the HomeController __construct() function doesn't have an auth middleware inside, that would try to log you in first, then continue to check for the index function.

Ad
source: stackoverflow.com
Ad