Home > Blockchain >  How to setup home page without requiring auth (Laravel)
How to setup home page without requiring auth (Laravel)

Time:06-07

I am trying to setup a standard homepage that every user has access to (and lands on), before they are routed to other pages after logging in.

Currently the web.php setup is

use App\Http\Controllers\HomeController;    
Route::get('/', [HomeController::class, 'home']->withoutMiddleware(['auth']));

The withoutMiddleware is to try and bypass the requirement of auth when trying to access the home.blade.php page, however I get the following error:

error message

Very new to Laravel, so any help would be greatly appreciated. Cheers!

CodePudding user response:

Routes don't require authentication unless it's explicitly specified in the routes web.php file or the controller.

So it can be as following:

use App\Http\Controllers\HomeController;    
Route::get('/', [HomeController::class, 'home'];

CodePudding user response:

Route::get('/', function () {
    if(Auth::guest()){
        return view('/home');
    }else{
        return redirect('/login');
    }
});
  • Related