laravel - Laravel 5.8 Multiple middlewares using guards and specific options for each guard
问题描述
I have a laravel application that allows both admins and customers to gain access to it and for each one of them will have specific permissions using 2 separated tables for each type of user to auth and 2 different guards. what I need now is to give customers access specific methods inside the controller and the admin have access to all methods.
class OrdersController extends Controller
{
public function __construct()
{
$this->middleware(['auth:client'])->only(['index', 'create', 'store', 'edit', 'printOrder']);
$this->middleware('auth:admin');
}
but it works fine for the client and it's not working for the admin
解决方案
You have two options
- define the desired middleware on the corresponding routes
Route::get('/some-route', [
'uses' => 'OrdersController@create',
'as' => 'create-order',
])->middleware('auth:client');
- check inside the method, if the correct auth took place
auth('auth:client')->check()
推荐阅读
- ruby - 如何为逻辑编写 rspec 并编写模拟 STDIN
- java - 如何修复无法解析 H2 数据库中的“DATE”常量问题?
- python - 如何在 pandas python 中使用 .iloc 将行写入 .csv 文件
- python - 将列数据类型更改为 timedateformat
- javascript - 这是反应路由器的预期行为还是错误?
- azure - 谁邀请了访客用户
- php - 如何修复 whereNotExists 和 where 查询生成器 laravel
- php - Laravel 强制替换 GET 参数
- android - 更新 NodeJs -> 添加 Android 时出错
- macos - macOS:无法在基于自定义 NSView 的类中居中 NSTextField