Warm tip: This article is reproduced from serverfault.com, please click

laravel-在null上调用成员函数middleware()

(laravel - Call to a member function middleware() on null)

发布于 2017-04-26 21:09:40

我在路由Laravel时使用以下中间件:

Route::group(['prefix' => 'api/'], function() {
    Route::resource('admin', 'adminController')->middleware('auth');
    Route::resource('profile', 'profileController')->middleware('role');
}); 

我在URL中调用“管理员”或“配置文件”路径时收到此错误 在此处输入图片说明

Questioner
ramzi trabelsi
Viewed
11
lagbox 2017-04-27 06:57:20

这是因为Route::resource()不返回任何东西。它的空虚。它不返回对象。

Laravel 5.4-照亮\ Routing \ Router @ resource

在Laravel 5.5(正在开发中)中,Route::resource()将返回一个对象以流畅地添加选项。