Middleware Auth for Resource Controller

I'm trying to use Laravel's auth middleware for a resource route. I have it setup as the code below, but the middleware is not applying and users are able to navigate directly to the page. If I try to specify the second parameter as an array and 'uses' => 'ResourceController' and specifying 'middleware' => 'auth' there (as you would with a get or other route), it errors saying it expects the parameter to be a string.

Route::resource('admin/resource', 'ResourceController', [
	'only' 	=> ['index', 'store'],
	'middleware' => 'auth'

What is the proper way to specify middleware when using a resource route?

ilkeruyank replied 3 years ago

you can use $this->middleware('auth') in your controller __construct method.

hoshomoh replied 3 years ago

please i have a new problem yeah. How do i write a resource middleware to make sure that he can only update his profile and not others

Obazure replied 11 months ago

You can use something like ``` Gate::class

answer here

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us