title: How to store and retrieve image contents from the database using Laravel
body: <p>I have to store and retrieve an image from the database.
  I want to store an image instead of image path or image name. When I searched for it I only found solutions for storing an image path or name. So can someone tell me how to store and retrieve an image with its size in KBs from database?</p>
  
  <p>This is my route.</p>
  
  <pre><code>Route::get('big_image/{id}/image', function ($id)
  {
     $user = big_image::find($id);
     return response()-&gt;make($user-&gt;image, 200, array(
     'Content-Type' =&gt; (new finfo(FILEINFO_MIME))-&gt;buffer($user-&gt;image)
  ));
  </code></pre>
  
  <p>});</p>
  
  <p>This is my controller</p>
  
  <pre><code> public  function new_store(Request $request ,$id){
      $event_id = $id;
      $img = new big_image;
      $file =  $request-&gt;file('image');
      $contents = $file-&gt;openFile()-&gt;fread($file-&gt;getSize());
      $img = big_image::find($id);
      $img-&gt;image = $contents;
      $img-&gt;image_name = $request-&gt;image_name;
      $img-&gt;event_id = $event_id;
      $img-&gt;save();
    $images=DB::table('big_image')-&gt;where('event_id','=',$event_id)-&gt;get();
    return view('image_upload',compact('images','id','response'));
  }
  </code></pre>
  
  <p>My display.blade.php file</p>
  
  <pre><code>@extends('app')
  @section('content')
    &lt;h2 style="text-align: center;margin-top: 10px;"&gt;Image Gallery&lt;/h2&gt;
    &lt;a href="{{url('pic_upload/'.$id.'')}}" class="col-sm-12"             style="padding-left: 0;"&gt;&lt;span&gt; add more pictures&lt;/span&gt;&lt;/a&gt;&lt;br&gt;
    &lt;a href="{{url('events')}}"&gt;&lt;span&gt;Back to events&lt;/span&gt;&lt;/a&gt;&lt;br&gt;
     @foreach($images as $item)
      &lt;div class="col-sm-4"&gt;
      {{--&lt;img src="data:image/jpeg;base64,'.base64_encode( $item-&gt;image  ).'"/&gt;;--}}
      &lt;/div&gt;
  @endforeach
  @stop
  </code></pre>