Laravel 5.4-为多租户应用程序添加前缀并应用两个中间件';s路线
我想对Laravel 5.4-为多租户应用程序添加前缀并应用两个中间件';s路线,laravel,authentication,laravel-5,middleware,Laravel,Authentication,Laravel 5,Middleware,我想对/account/{account\u id}进行分组,并使用auth中间件和一个中间件来保护其中的每条路由,该中间件将检查登录用户是否有权访问该帐户。不幸的是,它不起作用 这是我的密码 web.php: app/http/kernel.php 它甚至不会触发自定义中间件中的代码,我不明白为什么。我会使用策略(门),因为您可以将策略用作中间件 $ php artisan make:policy AcccountPolicy 在AuthServiceProvider中注册策略: /**
/account/{account\u id}
进行分组,并使用auth
中间件和一个中间件来保护其中的每条路由,该中间件将检查登录用户是否有权访问该帐户。不幸的是,它不起作用
这是我的密码
web.php:
app/http/kernel.php
它甚至不会触发自定义中间件中的代码,我不明白为什么。我会使用策略(门),因为您可以将策略用作中间件
$ php artisan make:policy AcccountPolicy
在AuthServiceProvider中注册策略:
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Account::class => AccountPolicy::class, //Account is model, remember to import!
];
在策略文件(app/policies/AccountPolicy.php)中,创建一个名为“manage”的方法
然后将此策略用作中间件:
Route::group(['prefix' => 'account/{account}', 'middleware' => 'can:manage,account'], function...
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Account::class => AccountPolicy::class, //Account is model, remember to import!
];
/**
* Determine if ....
*
* @param \App\User $current
* @param \App\Account $account
* @return bool
*/
public function manage(User $current, Account $account)
{
//return some logic here to check if $current is part of $account
}
Route::group(['prefix' => 'account/{account}', 'middleware' => 'can:manage,account'], function...