1
votes

I have these routes:

Auth::routes();
Route::get('/home', 'LibraryController@home');
Route::get('/', 'LibraryController@index');    

Auth::routes() is generated by the command php artisan make::auth. But, i don't want the index page to be under auth middleware group, the third route in the above list.

Here is the controller methods. index() is for everyone and home() for authenticated users.

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

    public function home()
    {
        return view('home')->with('message','Logged in!');
    }

the login users is redirected to home url:

protected $redirectTo = '/home';

But whenever i run the third route the login page appears. so, how can i remove that route from auth middleware group.

2
please a little explain your question its not clear what you are asking aboutRamzan Mahmood
you want to go to direct to home instead of index page??Ramzan Mahmood
@recoverymen no. i don't want Route::get('/', 'LibraryController@index'); route to be under auth middleware.Steve
you want that LibraryController@index here index method should not be authenticated mean every one can access ? is that your question ?Ramzan Mahmood
i don't see any routes under auth middleware unless you are calling auth middleware method from library controller constructor. if so, remove that method.Sanzeeb Aryal

2 Answers

2
votes

In your LibraryController before index where your controllers start you need to write

    public function __construct()
    {
        $this->middleware('auth', ['except' => ['index']]);
    }

Now every user will be able to go to index method without authentication

Documentation Reference https://laravel.com/docs/5.0/controllers#controller-middleware

0
votes

Since Laravel 7.7 you can use excluded_middleware property eg:

Route::group([
  'excluded_middleware' => ['auth'],
], function () {
  Route::get('/home', 'LibraryController@home');
  Route::get('/', 'LibraryController@index');   
});