您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CreateVendorSelect.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Filament\Forms\Components;
  3. use App\Filament\Company\Resources\Purchases\VendorResource;
  4. use App\Models\Common\Vendor;
  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 CreateVendorSelect extends Select
  11. {
  12. protected function setUp(): void
  13. {
  14. parent::setUp();
  15. $this
  16. ->searchable()
  17. ->preload()
  18. ->createOptionForm(fn (Form $form) => $this->createVendorForm($form))
  19. ->createOptionAction(fn (Action $action) => $this->createVendorAction($action));
  20. $this->relationship('vendor', 'name');
  21. $this->createOptionUsing(static function (array $data) {
  22. return DB::transaction(static function () use ($data) {
  23. $vendor = Vendor::createWithRelations($data);
  24. return $vendor->getKey();
  25. });
  26. });
  27. }
  28. protected function createVendorForm(Form $form): Form
  29. {
  30. return VendorResource::form($form);
  31. }
  32. protected function createVendorAction(Action $action): Action
  33. {
  34. return $action
  35. ->label('Create vendor')
  36. ->slideOver()
  37. ->modalWidth(MaxWidth::ThreeExtraLarge)
  38. ->modalHeading('Create a new vendor');
  39. }
  40. }