where('id', $id)->first(); } public function getRoleByCode(string $code): ?Role { return Role::query()->where('code', $code)->first(); } public function getRoles(RoleBuilderDto $roleBuilderDto, array $with = []): Search { $query = $this->builderCommand->execute( query: Role::query()->with($with), roleBuilderDto: $roleBuilderDto ); return $this->createSearchInstanceCommand->execute($query); } public function getRolesForSelect(array $withExcepts = []): array { return Role::query() ->when($withExcepts, function (Builder $query, array $withExcepts) { $query->withTrashed()->whereNull('deleted_at')->orWhereIn('id', $withExcepts); }) ->pluck('name', 'id') ->toArray(); } public function isExistsCode(string $code, ?int $exceptId = null): bool { return Role::query() ->where('code', $code) ->when($exceptId, function (Builder $query, int $exceptId) { $query->where('id', '!=', $exceptId); }) ->withTrashed() ->exists(); } }