As handy as it can be to store images in the database, sometimes you just want to store them in the Filesystem. Luckily this is relatively straightforward also. Imagine, for example, we just want to add an image for each Member of the tennis club and view it on the members index page. We just [...]
Category: Working with Images
This section describes how to allow user uploaded images to be stored, managed and displayed.
Adding user-uploaded Images - Step 1 - Storing images in the Database
There is much debate about the best way to handle images in a system. Images related to the look of the site itself are best treated as assets and stored as files in the file system with other assets. Images which are uploaded by users, however, can reasonably be base64 encoded and stored as a [...]
Adding user-uploaded Images - Step 2 - Rendering base64 encoded images on a view
Once the image has been uploaded to the database pulling that information and displaying it on the screen is simply a matter of understanding base64 encoded data. Base64 encoding data is a way of converting binary data into text data which makes it easier to process in html. This example will present an icon-sized image [...]
Adding multiple Images for an Entity - Step 1 - Creating a database table form to allow for multiple images to be uploaded.
If an entity (a person or an item) needs to have multiple images for each item then you will need an extra database entity and model to store those images. In the following example, we imagine a situation where each member of the tennis club can upload multiple images of themselves. Firstly, we need a [...]
Adding multiple Images for an Entity - Step 2 - Uploading the Images and saving them to the database
When the user uploads their various image files and submits the form the store() function of app/controllers/MemberimageController.php will be called. We now need to modify this function to allow it to process the array of files that will be uploaded. Modify the store() function that was generated by the scaffold replacing the code in the [...]
Adding multiple Images for an Entity - Step 3 - Displaying a collection of Images for an entity in a carousel
Once multiple images have been uploaded for an Entity in the database we need a simple way to display them without completely rebuilding the user interface. A bootstrap carousel is an ideal way to display multiple images. For the purposes of this example, we use the show.blade.php view and adapt it slightly to show the [...]