Installation:
composer require michaeld555/filament-croppie
php artisan filament-croppie:install
This publishes the config (config/filament-croppie.php) and translations.
Basic Usage in a Filament Form: Add the field to a Filament form resource:
use Michaeld555\FilamentCroppie\Fields\Croppie;
Croppie::make('avatar')
->image()
->required(),
First Use Case:
Basic Image Cropping:
Croppie::make('thumbnail')
->image()
->width(200)
->height(200)
->aspectRatio(1),
width/height: Set fixed dimensions.aspectRatio: Lock proportions (e.g., 4/3 for widescreen).Dynamic Configuration: Use closures for runtime adjustments:
Croppie::make('cover_image')
->image()
->width(fn () => $this->record->is_large ? 1200 : 800)
->height(600),
Integration with Storage:
Pair with Filament\Forms\Components\FileUpload for multi-step workflows:
$form->schema([
FileUpload::make('temp_image'),
Croppie::make('final_image')
->image()
->uploadFromField('temp_image'),
]);
Reusable Components: Extend the field for domain-specific logic:
class ProductImageCroppie extends Croppie {
protected string $view = 'filament-croppie::product-image';
public function configure(): static {
return $this->width(1024)->height(1024);
}
}
Validation: Combine with Filament’s validation rules:
Croppie::make('logo')
->image()
->required()
->rules('mimes:jpeg,png|max:2048'),
Missing Config:
php artisan vendor:publish --tag="filament-croppie-config") may break modal behavior or default values.Aspect Ratio Conflicts:
width/height and aspectRatio are set, the field prioritizes the ratio. Omit one dimension to avoid unexpected cropping.File Upload Paths:
upload_path in config points to a writable directory. Default: storage/app/public/croppie.JavaScript Conflicts:
Croppie::make('image')->view('filament-croppie::custom-view'),
Then override the view to wrap Croppie in a no-conflict scope.Large Files:
Croppie::make('hero_image')->compressQuality(0.7),
data-url or data-viewbox attributes).handleUpload event listener to debug file paths:
Croppie::make('image')->listen('handleUpload', fn ($path) => Log::info('Uploaded to:', $path));
resources/views/vendor/filament-croppie/field.blade.php) to customize UI or add tooltips.actions config:
Croppie::make('image')->actions([
'rotate' => 'Rotate 90°',
'flip' => 'Flip Horizontally',
]);
config(['filament-croppie.presets.thumbnail' => [
'width' => 300,
'height' => 300,
'aspectRatio' => 1,
]]);
Then use:
Croppie::make('thumbnail')->preset('thumbnail'),
saving event to process the cropped image before storage:
Croppie::make('image')->listen('saving', fn ($record, $state) => {
$image = Image::make($state['path'])->resize(800, 600);
$image->save($state['path']);
});
How can I help you explore Laravel packages today?