middleware for one specific method in controller in Laravel
The problem that you have when you added the middleware to $middlewareGroups
is explained in the doc
Out of the box, the web middleware group is automatically applied to your routes/web.php file by the RouteServiceProvider.
And if you want the middleware for just one action in the cotroller you can bind the middleware to the route :
Route::get('yourRout', 'YourController@actionX')->middleware('auth');
Or you can add it in constructor of your controller :
public function __construct(){ $this->middleware('auth', ['only' => ['edit']]);}
Or you can try ( Since Laravel 5.3) :
public function __construct() { $this->middleware('auth')->only(['edit']); }