spatie/laravel-medialibrary store files in DB only (pattern Builder ?) #3440
Replies: 1 comment 1 reply
-
So far I've only managed to do what I want by building the $path = Storage::path(
path: __('/path/folder/file')
);
$name = File::name($path);
$extension = File::extension($path);
$mimeType = File::mimeType($path);
$disk = config('filesystems.default');
$size = File::size($path);
$collectionName = 'collection';
$mediaClass = config('media-library.media_model');
/** @var Media $media */
$media = new $mediaClass();
$media->model_type = Model::class;
$media->model_id = $model->id;
$media->name = $name;
$media->file_name = "{$name}.{$extension}";
$media->mime_type = $mimeType;
$media->disk = $disk;
$media->conversions_disk = $disk;
$media->size = $size;
$media->collection_name = $collectionName;
$media->order_column = 1;
$media->custom_properties = [];
$media->generated_conversions = [];
$media->responsive_images = [];
$media->manipulations = [];
$media->save(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
As part of a Laravel application, I have files that are already present in my media public folder. However, when I seed my database (e.g.
php artisan migrate:fresh --seed
), I'd like to be able to store my media in the database (i.e. in the media table) without adding a file to my media folder (because there are already exist). Is this possible?I've tried this (but it breaks the image when storing, it still exists but I can't read it anymore)
The media is stored from DB and the file still exists but it's broken
Beta Was this translation helpful? Give feedback.
All reactions