<?php namespace App\Policies; use Illuminate\Auth\Access\HandlesAuthorization; use App\Models\{Netmail,User}; class NetmailPolicy { use HandlesAuthorization; /** * This determines whether a logged-in user can view a netmail * * @param User $user * @param Netmail $o * @return bool */ public function view(User $user, Netmail $o): bool { $addresses = $user->addresses()->pluck('id'); // Site Admins can always view return ( $user->isAdmin() || $user->isZC() || ($addresses->contains($o->fftn_id)) || ($addresses->contains($o->tftn_id)) ); } }