clrghouz/app/Models/Policies/EchomailPolicy.php

28 lines
514 B
PHP
Raw Permalink Normal View History

<?php
2024-11-04 07:25:49 +00:00
namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
use App\Models\{Echomail,User};
class EchomailPolicy
{
use HandlesAuthorization;
/**
* This determines whether a logged-in user can view an echomail
*
* @param User $user
* @param Echomail $o
* @return bool
*/
public function view(User $user, Echomail $o): bool
{
return (
$user->isAdmin()
|| $user->isZC()
|| $o->seenby->pluck('id')->intersect($user->addresses()->pluck('id'))->count()
);
}
}