-
app/Providers/AuthServiceProvider.php
Open in GitHubuse Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { protected $policies = [ 'App\\Model' => 'App\\Policies\\ModelPolicy', ]; // }
-
app/Models/Policies/ContactPolicy.php
Open in GitHubuse App\Models\Contact; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; class ContactPolicy { use HandlesAuthorization; public function update(User $user, Contact $contact) { if ($user->can('student.edit')) { return true; } if ($user->student) { return $user->student->id == $contact->student_id; } return false; } }
-
app/Http/Controllers/ContactController.php
Open in GitHubuse App\Models\Contact; class ContactController extends Controller { // public function edit(Contact $contact) { if (! backpack_user()->can('update', $contact)) { abort(403); } return view('students.edit-contact', [ 'contact' => $contact, 'redirect_url' =>url()->previous(), ]); } // }