Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5.4-为多租户应用程序添加前缀并应用两个中间件';s路线_Laravel_Authentication_Laravel 5_Middleware - Fatal编程技术网

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...