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
Lara Zeus
Lara Zeus16mo ago
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
awcodes
awcodes16mo ago
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.
Lara Zeus
Lara Zeus16mo ago
Would these be available in the component say on edit page?
awcodes
awcodes16mo ago
Why not.
Lara Zeus
Lara Zeus16mo ago
they're URL, when ever I use picsum.photos it wont show in the filepound component
awcodes
awcodes16mo ago
The 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.
awcodes
awcodes16mo ago
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.
awcodes
awcodes16mo ago
Would need to be modified for basic FileUpload, but the logic is there.
Lara Zeus
Lara Zeus16mo ago
that is a neat trick to know 🙂 thank you
awcodes
awcodes16mo ago
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.
Lara Zeus
Lara Zeus16mo ago
awcodes
awcodes16mo ago
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.
Lara Zeus
Lara Zeus16mo ago
yup I may send a PR for that 🙂 I needed to seed a grid more than 50 images so I use this
awcodes
awcodes16mo ago
Let’s call SOLID what it truly is, lazy. Lol.
Lara Zeus
Lara Zeus16mo ago
LSOLID
awcodes
awcodes16mo ago
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.
Lara Zeus
Lara Zeus16mo ago
yes sorry about that, also I hope you got the answer 🙂
Francisco García
Francisco GarcíaOP16mo ago
you're awesome thx
Want results from more Discord servers?
Add your server