laravel-5.8 - 中间件认证除了抛出错误方法
问题描述
我希望为客人显示视图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();
解决方案
你有:
$this->middlware('auth')->except('index', 'show');
中间件拼写错误,您的错误反映了这一点。它应该是:
$this->middleware('auth')->except(['index', 'show']);
推荐阅读
- javascript - 为什么抽屉在退出时没有动画?
- python - python raise JSONDecodeError("Expecting value", s, err.value) from None
- javascript - 如何更新 DocumentDB 中双嵌套数组中的嵌入文档
- reactjs - React - Axios 提出仅更新特定字段的请求
- python - 我怎样才能加快这个迭代?
- android - 使用 chrome 运行的 apk 的复制剪贴板权限被拒绝
- reactjs - 当每个项目在视图中滚动时为映射项目设置一次动画
- google-sheets - IMPORTRANGE 和 SUM 函数
- python - 之后从用户输入和打印列表运行while循环
- sql - 使用过程比较oracle sql server中每列的两个表