fdt2k / backpack-custom-fields
为 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-09-22 10:49:25 UTC
README
yarn
yarn mix
sail artisan vendor:publish --provider="KDA\Backpack\Field\CustomFieldServiceProvider" --tag="public" --force
可裁剪的图片字段
安装
sail composer require intervention/image
并遵循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;
]);
模型特质
将你的属性转换为数组并使用可裁剪特质
class Book extends Model {
use \KDA\Backpack\Field\Model\Croppable;
protected $casts = [
'cover'=> 'array',
...
]
protected $croppable = [
'cover'=>[ // field name
'path'=> 'press' // path in storage
]
];