1 month ago

how toretreive images from storage folder and display it in blade file

Posted 1 month ago by AbdulBazith

guys iam working with a project online examination.

the question may contain images and the options may also contain images. and the explanation may be images or docs.

while taking a question if there is image for the question it must be stored in storage folder and to be retrieved.

i have a column ques_mage in my table.

and my blade file to upload is

 <input name="ques_image" class="form-control" type="file" accept="image/*" onchange="document.getElementById('ques_image').src = window.URL.createObjectURL(this.files[0])">
                            <img id="ques_image" src=""  class="rounded-circle" width="150" height="150" >

my controller

 if ($request->hasfile('ques_image')) {

            $ques_image = $request->file('ques_image');

         $filename = $request->input('ques_no') . '-' .$ques_image->getClientOriginalName();

    $path = $ques_image->storeAs('QuestionImages', $filename);

             $addquestion->ques_image = $path;


here the image correctly stored in storage/app/QuestionImages folder. worked correctly.

and then i used php artisan storage:link this created a shortcut storage folder in my public folder.

now i need to display it in blade file.

i did like this

<img src="{{ asset('storage/app/'.$showques->ques_image) }}"> here i didnt mention the QuestionImages folder because the path stored in my table is with this folder name say for example QuestionImages/image.jpg like this

this is not working why???

and i have two doubts

  1. i need to store pdf and document also. if i need to store the documents means what should i do the same process?? and how can i show it in the blade file??

  2. why a storage shortcut created in public folder?

is this process correct?

and can i resize the image and store it in the storage folder?? because when displaying the question with options it looks so awkward to see. how can i make it unique

Kindly some help me pleasee.

Please sign in or create an account to participate in this conversation.