I'm wondering how I can set up middleware using a controller constructor and also reference middleware parameters as I've done successfully in my routes file.
I have this working fine in routes.php:
Route::group(['middleware' => 'user-type:user'], function () {
// routes
});
Now I want to do this within a controller constructor, but I'm getting some issues...
public function __construct()
{
$this->middleware = 'event-is-active:voting';
}
And when I visit a link with the above applied I get the following error:
ErrorException in ControllerDispatcher.php line 127:
Invalid argument supplied for foreach()
Of course I'm doing this wrong - I couldn't see how to do it in the docs and reading the source didn't help, but perhaps I overlooked something. So I'm wondering what is the right way and is it even possible? Any help would be most appreciated, thanks!