22 خطوط
510 B
PHP
22 خطوط
510 B
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\Attachment;
|
|
use App\Models\User;
|
|
use App\Support\AccessControl;
|
|
|
|
class AttachmentPolicy
|
|
{
|
|
public function view(User $user, Attachment $attachment): bool
|
|
{
|
|
return AccessControl::canAccessEntity($user, $attachment->attachable);
|
|
}
|
|
|
|
public function delete(User $user, Attachment $attachment): bool
|
|
{
|
|
return $this->view($user, $attachment)
|
|
&& ($user->hasRole('admin') || $attachment->uploaded_by === $user->id);
|
|
}
|
|
}
|