選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CreateClientSelect.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Filament\Forms\Components;
  3. use App\Filament\Company\Resources\Sales\ClientResource;
  4. use App\Models\Common\Client;
  5. use Filament\Forms\Components\Actions\Action;
  6. use Filament\Forms\Components\Select;
  7. use Filament\Forms\Form;
  8. use Filament\Support\Enums\MaxWidth;
  9. use Illuminate\Support\Facades\DB;
  10. class CreateClientSelect extends Select
  11. {
  12. protected function setUp(): void
  13. {
  14. parent::setUp();
  15. $this
  16. ->searchable()
  17. ->preload()
  18. ->createOptionForm(fn (Form $form) => $this->createClientForm($form))
  19. ->createOptionAction(fn (Action $action) => $this->createClientAction($action));
  20. $this->relationship('client', 'name');
  21. $this->createOptionUsing(static function (array $data) {
  22. return DB::transaction(static function () use ($data) {
  23. $client = Client::createWithRelations($data);
  24. return $client->getKey();
  25. });
  26. });
  27. }
  28. protected function createClientForm(Form $form): Form
  29. {
  30. return ClientResource::form($form);
  31. }
  32. protected function createClientAction(Action $action): Action
  33. {
  34. return $action
  35. ->label('Create client')
  36. ->slideOver()
  37. ->modalWidth(MaxWidth::ThreeExtraLarge)
  38. ->modalHeading('Create a new client');
  39. }
  40. }