1
私はプロジェクトの役割とアクセス許可を実装していますが、ポリシーを使用していますが、私は患者テーブルの新しいレコードの作成を許可するかどうかに問題があります。もの。 私はPatientPolicyでこれを持っているがLaravel 5の作成ポリシーに関する問題
// Only the users with root or admin roles can create patients;
public function create(User $user){
return ($user->hasRole('root') || $user->hasRole('admin'));
}
// only the patient creator can edit the patient and see the edit button
public function update(User $user, Patient $patient){
return $user->id == $patient->user_id;
}
AuthServiceProvider
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
'App\Patient' => 'App\Policies\PatientPolicy'
];
PatientController
public function edit(Patient $patient){
if(Gate::denies('update', $patient)){
abort(403, 'No esta autorizado de estar aqui');
}
return view('patients.edit', compact('patient'));
}
public function create(){
if(Gate::denies('create')){
abort(403, 'Usted no esta autorizado para crear pacientes');
}
return view('patients.create');
}
と私の意見
@can('create')
<li class="header">PROCESOS</li>
<li><a href="/paciente/create"><i class="fa fa-book"></i> <span>Apertura de Historia Clínica</span></a></li>
@endcan
問題で
はクレアということですアクションを実行することを許可されているユーザーに対しても、ポリシーは常にfalseを返しますが、編集ポリシーは完全に機能します。何か不足していますか?
可能な複製を[ Laravel 5.2で引数なしのポリシーメソッドを定義しますか?](http://stackoverflow.com/questions/37242321/how-to-define-a-policy-method-with-no-argument-in-laravel-5-2 ) –