我使用生成器生成一个简单的策略:
php artisan make:policy TeamPolicy
而且,我已在AuthServiceProvider
注册为:
protected $policies = [
Team::class => TeamPolicy::class,
];
我试图在TeamsController
中将其称为:
$this->authorize('update', $team);
以下是我的政策文件Policies\TeamPolicy.php
:
<?php
namespace App\Policies;
use App\Team;
use Illuminate\Auth\Access\HandlesAuthorization;
class TeamPolicy
{
use HandlesAuthorization;
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
//
}
public function update( Team $team)
{
App:debug("Policy update called!");
return true;
}
}
但是,从不调用策略中的更新方法,并且在调用$this->authorize('update', $team);
请指教!
答案 0 :(得分:2)
Policy方法的第一个参数应该是用户检查授权。请尝试改为:
public function update(User $user, Team $team)
{
//...
}