filament/spatie-laravel-media-library-plugin
v3.2.97
v11.19.0
v3.5.4
PHP 8.2.22
I have a form that accepts a PDF file upload (handled by the plugin). It also accepts a thumbnail image, but in case that is null the app generates a thumbnail from the first page of the PDF.
I've tried to hook into the afterCreate
lifecycle hook of the creation process to check for that. What happens is no media is available on the record, even though in the database row is added.
public function afterCreate(): void
{
if (!$record->getFirstMedia('thumbnail')) {
$pdf = $record->getFirstMedia('pdf');
$thumbnailGenerator = app(GenerateThumbnailFromPdf::class);
$record->addMedia($thumbnailGenerator->generate($pdf))->withResponsiveImages()->toMediaCollection('thumbnail');
}
}
In this instance $pdf
returns null. Note that I am not using database transactions.
I would expect to already have media available here in this lifecycle hook.
Forms\Components\SpatieMediaLibraryFileUpload::make('pdf')
->label('PDF File')
->collection('pdf')
afterCreate
method:public function afterCreate() {
$pdf = $this->record->getFirstMedia('pdf');
dd($pdf);
}
$pdf
should be an instance of Media here.
https://github.com/slovenianGooner/filament-issue-demo
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too