class UserSelect extends Select
{
protected ?string $defaultRole = null;
protected function setUp(): void
{
parent::setUp();
$this
->searchable(['first_name', 'last_name', 'company_name', 'email', 'phone'])
->getOptionLabelFromRecordUsing(fn (User $record) => $record->name)
->createOptionForm([
Group::make()
->schema(UserForm::getDetailsComponents())
->columns(2),
])
->createOptionUsing(function (array $data): int {
$user = User::create($data);
if ($this->defaultRole !== null) {
$user->assignRole($this->defaultRole);
}
return $user->getKey();
})
->createOptionAction(fn (Action $action, Select $select) => $action
->modalHeading($label = trim('Create ' . ($select->getLabel() ?? '')))
->modalSubmitActionLabel($label)
->modalWidth('3xl'),
);
}
public function role(string $role): static
{
$this->defaultRole = $role;
return $this;
}
}
class UserSelect extends Select
{
protected ?string $defaultRole = null;
protected function setUp(): void
{
parent::setUp();
$this
->searchable(['first_name', 'last_name', 'company_name', 'email', 'phone'])
->getOptionLabelFromRecordUsing(fn (User $record) => $record->name)
->createOptionForm([
Group::make()
->schema(UserForm::getDetailsComponents())
->columns(2),
])
->createOptionUsing(function (array $data): int {
$user = User::create($data);
if ($this->defaultRole !== null) {
$user->assignRole($this->defaultRole);
}
return $user->getKey();
})
->createOptionAction(fn (Action $action, Select $select) => $action
->modalHeading($label = trim('Create ' . ($select->getLabel() ?? '')))
->modalSubmitActionLabel($label)
->modalWidth('3xl'),
);
}
public function role(string $role): static
{
$this->defaultRole = $role;
return $this;
}
}