title: How to correctly load image blob from mysql database in laravel?
body: <p>I'm using laravel to display a list of items on a page. Each item has multiple images, but in this view I only want the first image to be displayed, but that doesn't really matter to the case.
  I believe I stored the image correctly since I can download a <code>.bin</code> file from the database and open it in the browser, which lets me view the image correctly. This database attribute is of type <code>BLOB</code>.</p>
  <p>So my item has a <code>hasMany</code> relation to the ItemImages table, which I try to use to access the image, but the image is never loaded and the src that is inserted is always something like <code>C:\xampp\tmp\php780D.tmp</code>.</p>
  <p>In the controller function I just fetch the data, like so:</p>
  <pre><code>public function item_index(){
      $itemsInDatabase = Item::all();
      return view('admin.item_index')-&gt;with('items',$itemsInDatabase);
  }
  </code></pre>
  <p>And so, in my view I access like this:</p>
  <pre><code>@foreach($items as $item)
      &lt;div class=&quot;col&quot;&gt;
          &lt;div class=&quot;card mb-3&quot; style=&quot;max-width: 540px;&quot;&gt;
              &lt;div class=&quot;row no-gutters&quot;&gt;
                  &lt;div class=&quot;col-md-4&quot;&gt;
                      &lt;img src=&quot;{{$item-&gt;item_images[0]-&gt;image}}&quot; alt=&quot;...&quot;/&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-md-8&quot;&gt;
                      &lt;div class=&quot;card-body&quot;&gt;
                          &lt;h5 class=&quot;card-title&quot;&gt;{{$item-&gt;name}}&lt;/h5&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  @endforeach
  </code></pre>
  <p>The data reaches the view correctly, since if I dump the <code>$item-&gt;item_images</code>, it shows all ItemImages objects associated with that item. So my problem is the actual render of this image in view.</p>
  <p>I wonder if I cannot use the relation to load the image, and I have to do some extra processing before declaring that image source attribute.</p>
  <p>As asked by @RiggsFolly , the upload script is like this:</p>
  <pre><code>if($files=$request-&gt;file('item_images')){
      foreach($files as $file){
          $newItemImage = new ItemImage();
          $newItemImage-&gt;image = $file;
          $newItemImage-&gt;item_id = $newItem-&gt;id;
          $newItemImage-&gt;save();
      }
  }
  </code></pre>
  <p>Thanks for your time!</p>