Lead::class, 'company' => Company::class, 'deal' => Deal::class, 'contact' => Contact::class, 'call' => Call::class, 'campaign' => Campaign::class, default => abort(422, 'نوع موجودیت پشتیبانی نمی‌شود.'), }; } public static function typeOf(Model $entity): string { return match (true) { $entity instanceof Lead => 'lead', $entity instanceof Company => 'company', $entity instanceof Deal => 'deal', $entity instanceof Contact => 'contact', $entity instanceof Call => 'call', $entity instanceof Campaign => 'campaign', default => 'unknown', }; } public static function authorize(string $type, int $id, string $ability = 'view'): Model { $entity = self::resolve($type, $id); Gate::authorize($ability, $entity); return $entity; } }