victorcamposramirez
victorcamposramirez
FFilament
Created by victorcamposramirez on 5/1/2025 in #❓┊help
Workaround for deleteOptionAction
I've struggled with this and I can't get it working. Anyone has any insight about it?
4 replies
FFilament
Created by victorcamposramirez on 4/25/2025 in #❓┊help
Upload image from table
For completion purposes, here is the code I used based on Dennis response:
ImageColumn::make('image')
->label('Imagen')
->disk('public')
->size(48)
->extraImgAttributes(['class' => 'rounded-lg'])
->action(Action::make('upload-image')
->modal()
->modalWidth('sm')
->modalHeading('Subir imagen')
->form([
FileUpload::make('image')
->label('Imagen')
->placeholder('Sube una imagen del producto')
->image()
->disk('public')
->directory('products')
->required(),
])
->fillForm(fn($record) => [
'image' => $record->image,
])
->action(fn($record, array $data) => $record->update([
'image' => $data['image'],
]))
),
ImageColumn::make('image')
->label('Imagen')
->disk('public')
->size(48)
->extraImgAttributes(['class' => 'rounded-lg'])
->action(Action::make('upload-image')
->modal()
->modalWidth('sm')
->modalHeading('Subir imagen')
->form([
FileUpload::make('image')
->label('Imagen')
->placeholder('Sube una imagen del producto')
->image()
->disk('public')
->directory('products')
->required(),
])
->fillForm(fn($record) => [
'image' => $record->image,
])
->action(fn($record, array $data) => $record->update([
'image' => $data['image'],
]))
),
4 replies
FFilament
Created by victorcamposramirez on 5/1/2025 in #❓┊help
Workaround for deleteOptionAction
I've also tried:
->editOptionAction(fn ($action) => $action->modalWidth('xs')
// Botón para eliminar la categoría de unidad de medida
->extraModalFooterActions(function ($action, $record) {
return [
DeleteAction::make()
->record($record->category)
->cancelParentActions()
];
})
)
->editOptionAction(fn ($action) => $action->modalWidth('xs')
// Botón para eliminar la categoría de unidad de medida
->extraModalFooterActions(function ($action, $record) {
return [
DeleteAction::make()
->record($record->category)
->cancelParentActions()
];
})
)
4 replies
FFilament
Created by victorcamposramirez on 3/11/2025 in #❓┊help
Customize Select in Relation Manager
No description
5 replies
FFilament
Created by victorcamposramirez on 3/11/2025 in #❓┊help
Customize Select in Relation Manager
No description
5 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
This way it shows the image, let the user change it, almost working perfect. But, It won't show the new image until I save changes on the form.
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
FileUpload::make('image')
->label('Imagen')
->avatar()
->placeholder(function ($record) {
if ($record && $record->mainImage()) {
$main_image = $record->mainImage();
$imagePath = asset("/storage/" . $main_image->path);
return <<<HTML
<img src="$imagePath" alt="Imagen principal" class="cropper-crop-box">
HTML;
}
})
->afterStateHydrated(function (Forms\Set $set, $record) {
if ($record?->mainImage()?->path) {
$imagePath = $record->mainImage()->path;
$set('image', ["/storage/".$imagePath]);
}
})
->required(),
FileUpload::make('image')
->label('Imagen')
->avatar()
->placeholder(function ($record) {
if ($record && $record->mainImage()) {
$main_image = $record->mainImage();
$imagePath = asset("/storage/" . $main_image->path);
return <<<HTML
<img src="$imagePath" alt="Imagen principal" class="cropper-crop-box">
HTML;
}
})
->afterStateHydrated(function (Forms\Set $set, $record) {
if ($record?->mainImage()?->path) {
$imagePath = $record->mainImage()->path;
$set('image', ["/storage/".$imagePath]);
}
})
->required(),
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
Here is my (not so better) code right now btw
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
I agree with you. Do you have any better approach?
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
No description
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
I'll admit I don't know how to set the input to the already uploaded image. So far I did this:
FileUpload::make('image')
->label('Imagen')
->avatar()
->afterStateHydrated(function (FileUpload $fileUpload, $record) {
if ( $record && $record->assets->where('is_primary', true)->count() > 0) {
$main_image = $record->assets->where('is_primary', true)->first();
$imagePath = asset("/storage/" . $main_image->path);
$fileUpload->placeholder(<<<HTML
<img src="$imagePath" alt="Imagen principal" class="cropper-crop-box">
HTML);
}
})
->required(),
FileUpload::make('image')
->label('Imagen')
->avatar()
->afterStateHydrated(function (FileUpload $fileUpload, $record) {
if ( $record && $record->assets->where('is_primary', true)->count() > 0) {
$main_image = $record->assets->where('is_primary', true)->first();
$imagePath = asset("/storage/" . $main_image->path);
$fileUpload->placeholder(<<<HTML
<img src="$imagePath" alt="Imagen principal" class="cropper-crop-box">
HTML);
}
})
->required(),
That's a better approach but I think I'm missing some method or concept to link the field state to the file without cheating the placeholder.
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
Thanks!
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
Ok I'll try and let you know the results 😉
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
But I need only the one with the field "is_primary" = true as a placeholder
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
The relationship in the model is defined as:
public function assets()
{
return $this->hasMany(ProductAsset::class);
}
public function assets()
{
return $this->hasMany(ProductAsset::class);
}
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
It's not the most elegant way tho
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
FileUpload::make('image')
->label('Imagen')
->avatar()
->placeholder(function ($record) {
if (! $record || ! $record->assets->first()) {
return false;
}

$mainImage = $record->assets->first();
$publicPath = asset('storage/' . $mainImage->path);

return <<<HTML
<img src="{$publicPath}" alt="{$record->name}" class="cropper-crop-box">
HTML;
})
->required(),
FileUpload::make('image')
->label('Imagen')
->avatar()
->placeholder(function ($record) {
if (! $record || ! $record->assets->first()) {
return false;
}

$mainImage = $record->assets->first();
$publicPath = asset('storage/' . $mainImage->path);

return <<<HTML
<img src="{$publicPath}" alt="{$record->name}" class="cropper-crop-box">
HTML;
})
->required(),
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
I've done a workaround
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
FileUpload (avatar) when record is in other model
There's no 'avatar' field on the database table really, is a related model ProductAsset
24 replies
FFilament
Created by victorcamposramirez on 3/5/2025 in #❓┊help
Change the size of RelationManager's create/edit modal?
Solved! My bad, I was trying in the form() method after schema()
4 replies