Premium Members Only
This advanced tutorial is available exclusively to Laravel Daily Premium members.
Join Premium - $29/month
Already a member? Login here
Premium membership includes:
Access to all premium tutorials
Video and Text Courses
Private Discord Channel
Comments & Discussion
PA
Any recommendation to import a large amount of media related with models? (user photos for example)
PK
PA
M
There's a few ways this can be done.
- Plain old Foreach, but that will quickly hit a timeout or something as it will depend on the users amount.
- Creating a job, that would create a user with X details and import Y image. Run a ton of those jobs via queue worker and it will import things.
In any case, you should have something like .csv file that already contains user information + their preferred image.
As for how, you can do it by:
$user->addMedia(\Storage::path('path_to_image'))->preservingOriginal()->toMediaCollection();
Just don't forget to preserve the original or make copies!
Very impressive package which I have used successfully in the past. FWIW services such as cloudinary & cloudflare images are very compelling alternatives and I now recommend their use. (Cloudinary more expensive but more powerful ... cloudflare super basic & cheap.) I use filepond for uploading (via livewire), which allows for size reduction & HEIC conversion on the client prior to server upload, so practical e.g. to upload iPhone photos which do not otherwise require the gigantic resolution.