Closed hasnatbabur closed 4 years ago
Done by nova fill callback.
Done by nova fill callback.
Hi, do you have an example ?
@gmarineau I had to override default "Filepond" Library field like below:
<?php
namespace App\Nova\Libraries;
use DigitalCreative\Filepond\Filepond as DCFilepond;
use Laravel\Nova\Http\Requests\NovaRequest;
class Filepond extends DCFilepond
{
/**
* @param NovaRequest $request
* @param string $requestAttribute
* @param object $model
* @param string $attribute
* @return mixed|void
*/
protected function fillAttributeFromRequest(
NovaRequest $request, $requestAttribute, $model, $attribute
)
{
// Just override and do nothing. This is handled by Nova callback and model event.
}
}
Then I had to use this custom extended field in Nova resource.
use App\Nova\Libraries\Filepond;
Filepond::make('Images', 'filepond_images')
->rules(['required'])->multiple()->limit(5)
->mimesTypes(['image/jpeg', 'image/png', 'image/gif'])
->disk(config('filesystems.default'))
->fillUsing(function($request, $model, $attribute, $requestAttribute){
// during creation images are handled by Nova Resource Observer
if($model->type !== post_type_image()) return;
// this runs only for update request
FilepondHelper::handleMediaByIdFillUsingCallback(PostMediaTag::images, true, $request, $model, $attribute, $requestAttribute); // only update
})
->resolveUsing(function($value, $resource, $attribute) use($request){
return FilepondHelper::handleMediaByIdResolveUsingCallback(PostMediaTag::images, $value, $resource, $attribute, $request);
}),
Then on "FilepondHelper" you need to implement your own filepond upload/fetch process.
Please feel free to ask if further help needed.
Thanks for this awesome plugin. We are using laravel-mediable library which handles attached media as separate many to many relationship.
Can you please give an option for entire store callback? The callback may be also empty function so that we can do other business logic with uploaded media path in model event.
Thanks.