Hey,
I am having this issue for some days now, and couldn't find the best approach.
I have a slider in my view that contains 3 images.
on the admin panel, I am giving the admin an option to upload the images to show on the slider.
What will be the best approach for uploading and storing the files?
Note:
the slider view should show the files in the order the admin has uploaded or chosen.
the number of images can increase when the admin wants. (means it can contain 4 images or more in the future)
I tried to save the files column as a json but it starts to do some problems when tried to show it on the view (maybe was doing it wrong..)
Then started thinking of giving 3 different inputs but that way will be difficult to maintain when the admin will want to increase the number of images
you can add a boolean type column in your table as is_active or active and in your upload view list all your image records and have an option for the admin to activate or deactivate a particular image.
then in your slider only show those with status active or is_active ==truedepending on what name your column.
$images = Image::whereIsActive(true)->get();
this way you won't have to set a counter for the slider and the slider will show only the activated images no matter how many.
If you need more control over on slider you need to create a new table for slider
for example
id | slidername | image | order | created_at | updated_at
Table entries
1 | home | /photos/cat-1.png | 2
1 | home | /photos/cat-2.png | 1
1 | home | /photos/cat-3.png | 3
1 | about | /photos/dog-1.png | 3
1 | about | /photos/dog-2.png | 2
1 | about | /photos/dog-3.png | 1