Added method getRolesForSelect in the RoleRepository.

This commit is contained in:
Leonid Nikitin 2023-08-01 22:09:06 +06:00
parent 73d99a0432
commit 9c1ed593b5
Signed by: kor-elf
GPG Key ID: 7DE8F80C5CEC2C0D

View File

@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Builder;
final readonly class RoleRepository final readonly class RoleRepository
{ {
final public function __construct( public function __construct(
private CreateSearchInstanceCommand $createSearchInstanceCommand, private CreateSearchInstanceCommand $createSearchInstanceCommand,
private BuilderCommand $builderCommand private BuilderCommand $builderCommand
) { } ) { }
@ -36,6 +36,16 @@ final readonly class RoleRepository
return $this->createSearchInstanceCommand->execute($query); 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 public function isExistsCode(string $code, ?int $exceptId = null): bool
{ {
return Role::query() return Role::query()