passes($user, $note, 'manage-all-notes'); } public function viewNotes(User $user, ?Note $note = null) { return $this->passes($user, $note, 'view-all-notes'); } /** * Bouncer is asked about the note itself where there is one and about the * class otherwise. Membership is only meaningful in the first case: a * class-level question carries no company to test the user against. * * Note that the ability is resolved for whoever is logged in rather than * for `$user`, which is what the facade does; only the membership half of * the decision actually reads the argument. */ private function passes(User $user, ?Note $note, string $ability): bool { if (! BouncerFacade::can($ability, $note ?? Note::class)) { return false; } if ($note === null) { return true; } return $user->hasCompany($note->company_id); } }