title: Image Preview from DB
body: <p>I'm Trying to Preview images from database as im saving album in table albums and album images in table images and connecting with relation but i can't preview the images from table image so i'm adding relations between the 2 tables and trying to preview the images but its not working with me something went wrong but i cannot figure it</p>
  <p>Blade.php</p>
  <pre><code>&lt;tbody&gt;
  @foreach ($albums as $album)
  
  &lt;tr&gt;
      &lt;th scope=&quot;row&quot;&gt;{{$album-&gt;id}}&lt;/th&gt;
      &lt;td&gt;{{$album-&gt;name}}&lt;/td&gt;
      &lt;td&gt;{{$album-&gt;category_id}}&lt;/td&gt;
      &lt;td&gt;&lt;img style=&quot;width:5vw; hieght:5vh&quot; src=&quot;{{$album-&gt;id}}&quot; alt=&quot;&quot;&gt;&lt;/td&gt;
      &lt;td&gt;
          &lt;a href=&quot;{{route('albums.show',$album-&gt;id)}}&quot; class=&quot;btn btn-success&quot;&gt;Show&lt;/a&gt;
          @if (Auth::user()-&gt;role_id==1)
          &lt;a href=&quot;{{route('albums.edit',$album-&gt;id)}}&quot; class=&quot;btn btn-warning&quot;&gt;Edit&lt;/a&gt;
          &lt;form action=&quot;{{route('albums.destroy',$album-&gt;id)}}&quot; method=&quot;post&quot; class=&quot;d-inline&quot;&gt;
          @csrf
          @method('DELETE')
              &lt;input type=&quot;submit&quot; class=&quot;btn btn-danger&quot; value=&quot;Delete&quot; /&gt;
          &lt;/form&gt;
  @else
  @endif
  
      &lt;/td&gt;
  &lt;/tr&gt;
  @endforeach
  &lt;/tbody&gt;
  
  </code></pre>
  <p>AlbumsController</p>
  <pre><code>    public function index()
      {
          $albums = Album::with('images')-&gt;get();
                  return view('admin.albums.all',compact('albums'));
      }
  
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {
          $albums=Album::all();
          $categories=Category::all();
          return view('admin.albums.create',compact('categories'));
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
  
          $album=Album::create([
              'name'=&gt;$request-&gt;name,
              'price'=&gt;$request-&gt;price,
              'image'=&gt;$request-&gt;image,
              'category_id'=&gt;$request-&gt;category_id,
          ]);
          foreach($request-&gt;images as $image){
              $filename = $image-&gt;store('album');
              $images=Image::create([
                  'album_id' =&gt; $album-&gt;id,
                  'filename' =&gt; $filename
              ]);
          }
          $albums=Album::with('images')-&gt;get();
          return view('admin.albums.all',compact('albums'));
      }
  
  </code></pre>
  <p>Image Model</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Image extends Model
  {
      use HasFactory;
      protected $fillable = ['album_id','filename'];
  
      public function images(){
          return $this-&gt;belongsTo(Album::class,'id');
      }
  }
  
  </code></pre>
  <p>Album Model</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Album extends Model
  {
      use HasFactory;
      protected $fillable = [
          'name',
          'category_id',
      ];
      public function categories(){
          return $this-&gt;belongsTo(Category::class,'category_id','id');
      }
      public function images(){
          return $this-&gt;HasMany(Image::class,'filename','id');
      }
  }
  
  </code></pre>
  <p>table images Migration</p>
  <pre><code>&lt;?php
  
  use Illuminate\Database\Migrations\Migration;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Support\Facades\Schema;
  
  return new class extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('images', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;biginteger('album_id')-&gt;unsigned();
              $table-&gt;foreign('album_id')-&gt;references('id')-&gt;on('albums');
              $table-&gt;string('filename');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('images');
      }
  };
  
  </code></pre>
  <p>Table albums Migration</p>
  <pre><code>&lt;?php
  
  use Illuminate\Database\Migrations\Migration;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Support\Facades\Schema;
  
  return new class extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('albums', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;string('name');
              $table-&gt;integer('category_id');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('albums');
      }
  };
  
  </code></pre>