Support the ongoing development of Laravel.io →
Input Session Packages
Last updated 2 years ago.
0

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?

0

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
0

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');
});
0

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.

0

Indeed, though this doesn't explain why the middleware is not loaded when the middleware is specified in the controllers constructor.

0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.