laravel-medialibrary: Return value of Spatie\MediaLibrary\PathGenerator\BasePathGenerator::getBasePath() must be of the type string, null returned
Getting an error in Laravel 6.2
Symfony\Component\Debug\Exception\FatalThrowableError
Return value of Spatie\MediaLibrary\PathGenerator\BasePathGenerator::getBasePath() must be of the type string, null returned
vendor/spatie/laravel-medialibrary/src/PathGenerator/BasePathGenerator.php:39
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 7
- Comments: 22 (5 by maintainers)
I had this error and it occurred because I didn’t save the model first
$model->save()before creating media to attach and calling$media->getUrl()So check to make sure you save the model first and it exists in the database if you are calling that method.
This issue was again introduced in version 9.8.3
Let me add to this by saying, if you query media items directly and use an implicit
->select('etc')in the query, you must include the ‘conversion_disk’ column in your select to avoid problems.@vlados if you already know a solution, feel free to PR the fix + tests to make sure the bug isn’t introduced again.