Pantlock
Pantlock
FFilament
Created by Pantlock on 6/25/2024 in #❓┊help
FileUpdload not displaying file preview
Firstly, yes.. I linked the storage folder to the public folder. I have a model Event that has a nullable string column image. I want to have a default image that is displayed on the frontend when image is uploaded. The default image is at public/img/event/default-event.png The uploaded files from Filament should go to storage/app/public/event/xxx.png (public/storage/event/xxx.png) Currently, I have defined an Accessor on the model:
protected function image(): Attribute
{
return Attribute::make(
get: fn (?string $value) => Storage::url($value) ?? self::DEFAULT_IMAGE,
);
}
protected function image(): Attribute
{
return Attribute::make(
get: fn (?string $value) => Storage::url($value) ?? self::DEFAULT_IMAGE,
);
}
That Storage::url($value) is causing trouble for Filament, as it doesn't show the file preview when used with the FileUpload form component. For reference, this is the component in use:
Forms\Components\FileUpload::make('image')
->directory('img/event')
->image()
->imageEditor()
->downloadable()
->imageEditorAspectRatios([
null,
'16:9',
])->optimize('jpg'),
Forms\Components\FileUpload::make('image')
->directory('img/event')
->image()
->imageEditor()
->downloadable()
->imageEditorAspectRatios([
null,
'16:9',
])->optimize('jpg'),
1 replies
FFilament
Created by Pantlock on 6/13/2024 in #❓┊help
Reorderable with descending order
Hi, I have an app with a resource that I want to be reorderable, but with a descending order. I am using the spatie/eloquent-sortable package fot the order_column. In the filament resource file, I have the ->defaultSort('order_column', 'desc') that changes the order when just viewing all the records. Then of course I have the ->reorderable('order_column') on the table as well. Has anyone dealt with the fact that the reorderable uses ascending order? I would like the order to stay the same when viewing and editing the records. Is there some simple workaround?
4 replies
FFilament
Created by Pantlock on 8/27/2023 in #❓┊help
Data type for FileUpload
I have simple Page, generated with php artisan make:filament-page In there I have a Form with multiple components, one of them being FileUpload (for uploading image). The property I want to use to store the image name is $quote_1_image. In databases this column is a string.
public ?string $quote_1_image;

public function mount(): void
{
$this->homePage = \App\Models\Pages\HomePage::find(1);
$this->form->fill($this->homePage->toArray());
}

public function form(Form $form): Form
{
return $form->schema([
Forms\Components\FileUpload::make('quote_1_image')
->image(),
...
public ?string $quote_1_image;

public function mount(): void
{
$this->homePage = \App\Models\Pages\HomePage::find(1);
$this->form->fill($this->homePage->toArray());
}

public function form(Form $form): Form
{
return $form->schema([
Forms\Components\FileUpload::make('quote_1_image')
->image(),
...
I'm however getting this error: Cannot assign array to property App\Filament\Pages\HomePage::$quote_1_image of type ?string When I change the datatype to array, the error says: Cannot assign string to property App\Filament\Pages\HomePage::$quote_1_image of type ?array
2 replies