Files Seeding good practice
I have a project with images, I'm managing your single file and multiple file input with filepond, no spatie or similar, but I need to seed these scenarios using seeders, what could be a good practice to seed this following your way to work?
Do you have any documentation? thanks!
18 Replies
upload a file, and save it,
take the value from the database and put it into the seeder
it will be something like:
files/AkE74BxCf1wwSX6RNwY0u8pgtUyEM0-metac2h1YmhhbS1kaGFnZS00dTdWekRnTmdMSS11bnNwbGFzaC5qcGc=-.jpg
faker()->image()
In curator I just added some images to a free cloudinary account then I can grab one at random to use in a factory.
Would these be available in the component say on edit page?
Why not.
they're URL, when ever I use
picsum.photos
it wont show in the filepound componentThe factory just uses file_get_contents to get the data for the image then saves it using storage then the storage->path() is saved to the db field.
GitHub
filament-curator/database/factories/MediaFactory.php at 3.x · awcod...
A media picker plugin for Filament Panels. Contribute to awcodes/filament-curator development by creating an account on GitHub.
Would need to be modified for basic FileUpload, but the logic is there.
that is a neat trick to know 🙂 thank you
The filament demo uses unsplash, but since unsplash caches / throttles requests you’ll end up with a lot of the same image. Which is fine in a seeder but I don’t like it personally.
ya this is better than unseplash
https://picsum.photos/200/300?random=faker-.>random
If you look at the demo, you’ll see that like every ten products in a row all have the same image. Like I said not bad for a seeder when developing, it just bothers me personally. I hate seeing it in a table that way.
But I also wanted to provide a sensible factory in curator because I use it in several projects and didn’t want to rewrite the seeder every time.
yup I may send a PR for that 🙂
I needed to seed a grid more than 50 images so I use this
Let’s call SOLID what it truly is, lazy. Lol.
LSOLID
Yea. I don’t mind duplicates which is why it’s only a pool of like 15 images, but with random it just decreases the amount of duplicate images on back to back records.
Sorry we hijacked your question @franciscodaniel.gn
Hopefully it’s of use.
yes sorry about that, also I hope you got the answer 🙂
you're awesome
thx