remocodebe / laravelnova-filepond
使用 filepond 上传文件、图片和视频的 Nova 字段。
0.2.14
2021-10-05 11:46 UTC
Requires
- php: >=7.1.0
README
使用 Filepond 上传文件、图片和视频的 Nova 字段。
安装
您可以通过 composer 安装此包
composer require remocodebe/laravelnova-filepond
用法
use DigitalCreative\Filepond\Filepond; class Post extends Resource { public function fields(Request $request) { return [ // ... Filepond::make('Audio Example') ->multiple() // the default is single upload, use this method to allow multiple uploads ->limit(4) // limit the number of attached files ->rules('required') // every validation rule works!! ->mimesTypes([ 'audio/mp3', 'audio/ogg', 'audio/vnd.wav' ]) // if opmited, accepts anything ->disk('public', '/optional/location') // the second argument instruct the file to be stored into a subfolder ->storeAs(function (Illuminate\Http\File $file) { // this is optional, use in case you need generate custom file names return Str::random(20) . '.' . $file->getExtension(); }) ]; } }
当上传多个文件时,您需要在模型类中将属性转换为数组
class Post extends Model { /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'images' => 'array' ]; }
添加图像编辑器
要为用户启用图像编辑,您必须添加 Doka Image Editor。
-
获取编辑器的许可证并下载 Doka 库文件。
-
发布配置文件
php artisan vendor:publish --provider="DigitalCreative\Filepond\FilepondServiceProvider" --tag="config"
- 将
doka.enabled
设置为true
并更新doka.min.js
和doka.min.css
库文件的路径。
'doka' => [ 'enabled' => true, 'js_path' => public_path('doka.min.js'), // this assumes you places theses files within your public directory 'css_path' => public_path('doka.min.css'), ]
- 有两个选项可用于在特定字段上启用/禁用 Doka,
->withDoka($options)
接受选项列表,您可以在以下位置找到所有可能的选项的文档:https://pqina.nl/doka/docs/patterns/api/doka-instance/#properties
public function fields(Request $request) { return [ //... Filepond::make('Avatar')->withDoka([ 'cropShowSize' => true ]), /** * This will disable Doka for this specific field */ Filepond::make('Simple Image')->withoutDoka(), ]; }
如果一切设置正确,您应该在 FilePond 图片的顶部看到编辑图标。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。