我有一个Evaluation模型,它与User有关系。我试图使用Laravel来保护评估路线,只允许指定的用户访问他们的评估。我以前从未使用过盖茨,也似乎无法让盖茨工作并不断地得到Too few arguments to function App\Providers\AuthServiceProvider::App\Providers\{closure}(), 1 passed in /Users/charles/Documents/Development/seedgen/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 536 and exactly 2 expected错误。我知道我需要提出更多的论点,但我被困住了。
AuthServiceProvidor.php
...
public function boot()
{
$this->registerPolicies();
Gate::define('showEval', function (User $user, Evaluation $evaluation) {
return $user->id === $evaluation->user_id;
});
}
...Show.php
...
public function render()
{
if (Gate::allows('showEval')) {
return view('livewire.evaluation.show');
} else {
abort(403);
}
}
...发布于 2022-06-15 09:00:23
你没有通过$evaluation来办理登机手续
public function render()
{
// somehow getting $evaluation you want to pass to gate check
if (Gate::allows('showEval', $evaluation)) {
return view('livewire.evaluation.show');
} else {
abort(403);
}
}根据文档门本身获取当前用户,所以通过第二个param就在您身上。
https://stackoverflow.com/questions/72627714
复制相似问题