What were you doing that caused this:
Line because I was getting call to middleware() on null object or some such thing.
What line of code and what did the stacktrace say?
This is the line in my package route file:
Route::resource('role_groups', 'KevinOrriss\UserRoles\Controllers\RoleGroupController')->middleware('web');
When I run: php artisan route:list
I get:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to a member function middleware() on null
Also, just to confirm, I changed to this and it works fine:
Route::group(['middleware' => ['web', 'auth']], function () {
Route::resource('roles', 'KevinOrriss\UserRoles\Controllers\RoleController');
Route::resource('role_groups', 'KevinOrriss\UserRoles\Controllers\RoleGroupController');
});
Yea if you look at the definition of Router@resource
it does not return anything. It just registers a bunch of routes, there isn't anything for it to return.
Indeed, though this doesn't explain why the middleware is not loaded when the middleware is specified in the controllers constructor.
I was looking around about this, "Call to a member function middleware() on null"
All this doesn't work
Route::resource('articles','ArticlesController', ['middleware'=>['auth']]);
Route::resource('articles','ArticlesController')->middleware('auth');
You have to
Route::group('middleware'=>'auth', function(){
Route::resource('articles','ArticlesController')
});
or set it $this->middleware('auth') in the controller's constructor
dunno why the documentation doesn't say nothing about this
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community