File::make(__('Attachment'), 'attachment')
->acceptedTypes('.pdf')
->disk('s3')
->path('ly/contents')
->store(function (Request $request, $model) {
$s3filePath = $request->attachment->store('ly/contents', 's3');
$model
->addMediaFromDisk($s3filePath, 's3')
->toMediaCollection('pdf');
return [
'attachment' => $s3filePath
];
})->onlyOnForms(),
# I have no attachment field in the database, so I use next fillFields function to fix this.
// https://github.com/laravel/nova-issues/issues/2334#issuecomment-709422756
protected static function fillFields(NovaRequest $request, $model, $fields)
{
$fillFields = parent::fillFields($request, $model, $fields);
// first element should be model object
$modelObject = $fillFields[0];
// remove all attributes do not have relevant columns in model table
unset($modelObject->attachment);
return $fillFields;
}