label(__('filament.actions.models.wiki.upload_image.name')); $this->facets([ ImageFacet::GRILL, ImageFacet::DOCUMENT, ]); $this->visible(function ($livewire) { if (Auth::user()->cannot('create', Image::class)) { return false; } return $livewire instanceof BaseListResources; }); } /** * Perform the action on the table. * * @param array $fields * @return void */ public function handle(array $fields): void { $image = Arr::get($fields, Image::ATTRIBUTE_PATH); $facet = ImageFacet::from(intval(Arr::get($fields, Image::ATTRIBUTE_FACET))); $this->createImageFromFile($image, $facet); } /** * Get the fields available on the action. * * @param Form $form * @return Form */ public function getForm(Form $form): Form { $options = []; foreach ($this->facets as $facet) { $options[$facet->value] = $facet->localize(); } return $form ->schema([ Select::make(Image::ATTRIBUTE_FACET) ->label(__('filament.fields.image.facet.name')) ->helperText(__('filament.fields.image.facet.help')) ->options($options) ->required() ->enum(ImageFacet::class), FileUpload::make(Image::ATTRIBUTE_PATH) ->label(__('filament.fields.image.image.name')) ->required() ->image() ->imageEditor() ->imageEditorAspectRatios([null, '2:3']) ->storeFiles(false), ]) ->columns(1); } /** * Get the facets available for the action. * * @param ImageFacet[] $facets * @return static */ public function facets(array $facets): static { $this->facets = $facets; return $this; } }