fdt2k / backpack-custom-fields
Custom fields for backpack
2.0.9
2022-07-25 17:00 UTC
Requires
- fdt2k/laravel-json: dev-main
- fdt2k/laravel-package-service-provider: dev-master || dev-master-2 || 1 - 2
- intervention/image: ^2.7
- jenssegers/date: ^4.0
This package is auto-updated.
Last update: 2024-10-22 10:58:38 UTC
README
yarn
yarn mix
sail artisan vendor:publish --provider="KDA\Backpack\Field\CustomFieldServiceProvider" --tag="public" --force
Croppable Image Field
install
sail composer require intervention/image
and follow https://image.intervention.io/v2/introduction/installation#integration-in-laravel
CRUD::addField([
'label' => "Couverture",
'name' => "cover",
'type' => 'imagecrop',
'tab'=> 'Media',
// imagecrop
'original_field'=> 'original',
'metadata_field'=> 'crop',
'crop' => true, // set to true to allow cropping, false to disable
'aspect_ratio' => 1, // omit or set to 0 to allow any aspect ratio
//'crop' => true, // set to true to allow cropping, false to disable
//'aspect_ratio' => 1, // omit or set to 0 to allow any aspect ratio
// 'disk' => 's3_bucket', // in case you need to show images from a different disk
// 'prefix' => 'uploads/images/profile_pictures/' // in case your db value is only the file name (no path), you can use this to prepend your path to the image src (in HTML), before it's shown to the user;
]);
Model trait
cast your attribute as array and use the Croppable trait
class Book extends Model {
use \KDA\Backpack\Field\Model\Croppable;
protected $casts = [
'cover'=> 'array',
...
]
protected $croppable = [
'cover'=>[ // field name
'path'=> 'press' // path in storage
]
];