我希望向访客显示listings
和showlisting
页面(无需登录)。
使用时:
$this->middleware('auth';
在我的ListingsController
的构造函数中,一切正常(对于已登录的用户),但是当我使用以下方法排除索引并显示方法时:
$this->middlware('auth')->except('index','show');
我收到此错误:
BadMethodCallException方法 App \ Http \ Controllers \ ListingsController :: middlware不存在。
我搜索了几天,但没有找到任何解决方法。
ListingsController.php
public function __construct()
{
$this->middlware('auth')->except('index', 'show');
}
web.php(路由文件)
Route::get('/', 'ListingsController@index');
Route::resource('listings', 'ListingsController');
Route::get('/dashboard', 'DashboardController@index');
Auth::routes();
答案 0 :(得分:0)
您有:
$this->middlware('auth')->except('index', 'show');
中间件拼写错误,您的错误反映了这一点。应该是:
$this->middleware('auth')->except(['index', 'show']);