Practical work: Agence immo, images — Discovery training of Laravel 10
In this chapter we will set up the system for sending images for our assets. We will allow our users to send multiple images to illustrate the ads.
To set up this system we will need to create a new model Picture
which will represent an image. This model will be linked to our model Property
via a relation of the type belongsTo
. When the user sends several images, we will create as many Picture
necessary and we will use the system of Storage
to send the files to the correct folder.
We will also seek to allow the administrator to be able to easily delete any image that has been previously associated with an asset. For this we will use the htmx library which will allow us to create an easy-to-use interface for this deletion. This will allow us to make an Ajax request when the user clicks on the delete button and allows us to perform the deletion without necessarily having to change the page (and losing the form information at the same time).
Finally, we will use Glide to resize the images to the correct format.