2

So I have a Resource controller and it's route defined as below:

Route::resource('product', 'App\Http\Controllers\ProdutoController')->middleware('auth');

But, I wanted to not-logged in user to be able to acces the "show" method inside that controller. How can I apply the "auth" middleware to every method inside the controller except the "show" method?

  • **you can find your solution from here:** [more details...](https://stackoverflow.com/questions/28729228/laravel-5-resourceful-routes-plus-middleware) – Mustafa Poya Nov 03 '20 at 09:30

1 Answers1

1

Inside your ProdutoController you can use the construct method to apply the authentication middleware and except some routes like this:

/**
     * Instantiate a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth')->except(['index', 'show']); 
    }
Ali Ali
  • 1,756
  • 2
  • 15
  • 34