Adding Images to Posts and Subweddits using Storage
I've left this part of the project until the posts and subweddits were completed to avoid over-complicating things, as I know its a case of a simple migration and a bit of fiddling in the controller from this point.
Both subweddits and posts will have some sort of file upload, in the form of an image. Subweddits will have their logo, which is mandatory, and posts can have an optional image upload.
We must first make a migration to add_logo_to_subweddit and add_img_to_post. Besides the names of the fields, the migration looks the same.
These are both the frontend and backend of the new file upload.
These files could be anything, so require both clientside and serverside validation, but these will be attempted later on, I'll focus on the functionality first.
Once the data is passed to the controller, there must be a way to save the data, for that we need to import 'Storage' [do full path], and set the path of the image to the logo/img/field. so save being confused, I'm going to organise my laravel storage directory a bit, so that all data is kept in a folder of the subweddits name, with post images being kept in a further subfolder named 'posts'.
For these to be accessable, I will create a route to the image or logo under w/{subweddit}/{post}/img and w/{subweddit}/logo respectively, where they are publicly available.
When calling these, we make a request to the routes containing the logo and the image, which will pull the image and display it on the blade.
Comments
Post a Comment