title: Show all data according to product_id in laravel-8
body: <p>This is my projects table. Can anyone help me? I am stuck on this for 2 day</p>
  <p>I can show here datas of products table
  <a href="https://i.stack.imgur.com/LVr8x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LVr8x.png" alt="enter image description here" /></a>
  You can see every product or app have unique id with button like if i click id 6 it will take me to next page where I can upload an excel file in project table. so things is like this App id:6 can have many projects data which can be upload form excel file. and every data of excel file have id</p>
  <p>This is products table
  <a href="https://i.stack.imgur.com/tE3eq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tE3eq.png" alt="enter image description here" /></a>
  This is where i can create products
  <a href="https://i.stack.imgur.com/pAdrs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pAdrs.png" alt="enter image description here" /></a>
  If i click save and next i can upload excel file</p>
  <p>This id projects table</p>
  <p><a href="https://i.stack.imgur.com/nHXk4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nHXk4.png" alt="enter image description here" /></a>
  You can see in my project table I can store data according to <code>product_id</code>. In my projects table I have three <code>product_id</code> 1, 2, 3. I want to show them according to <code>product_id</code>. For example, if I want to show data of <code>product_id</code> 2 then in my index.blade.php will show only data of <code>product_id</code> 2 not product_id 1 and 3</p>
  <p>This is my <code>index()</code> method of projectController.php</p>
  <pre><code>public function index()
      {
          $product = Product::with('projects')-&gt;where('user_id', Auth::id())-&gt;firstOrFail();
          $projects = $product-&gt;projects()-&gt;latest()-&gt;paginate(20);
  
          return view('projects.index', compact('projects'))
              -&gt;with('i', (request()-&gt;input('page', 1) - 1) * 5);
      }
  </code></pre>
  <p>This is my <code>show()</code> method in my ProjectController.php</p>
  <pre><code>public function show(Project $project)
      {
          return view('projects.show', compact('project'));
      }
  </code></pre>
  <p>This is user model user.php</p>
  <pre><code> public function Products(){
          return $this-&gt;hasMany('App\Models\Product');
  
      }
  
      public function Project(){
          return $this-&gt;hasMany('App\Models\Project');
      }
  </code></pre>
  <p>This is product model product.php</p>
  <pre><code>class Product extends Model
  {
      use HasFactory;
  
      protected $fillable = [
          'name', 'detail', 'image','color','logo','user_id'
      ];
  
      public function User(){
          return $this-&gt;belongsTo(User::class);
      }
  
      public function Project(){
          return $this-&gt;hasMany(Project::class);
      }
  }
  </code></pre>
  <p>This is project model project.php</p>
  <pre><code>class Project extends Model
  {
      use HasFactory;
  
      protected $fillable = [
          'chapter_name',
          'sub_section_name',
          'title_1',
          'description_1',
          'image_1',
          'image_2',
          'image_3',
          'title_2',
          'description_2',
          'title_3',
          'description_3',
          'video_1',
          'video_2',
          'video_3',
          'user_id',
          'product_id'
      ];
  
      public function User(){
          return $this-&gt;belongsTo(User::class);
      }
  
      public function Product(){
          return $this-&gt;belongsTo(Product::class);
      }
  }
  </code></pre>
  <p>This is projectImport.php where i can upload execl</p>
  <pre><code>class ProjectsImport implements ToModel, WithHeadingRow
  {
  
      public function __construct()
      {
          Project::where('product_id',Product::where('user_id',Auth::id())-&gt;pluck('id')-&gt;last())-&gt;delete();
      }
      /**
       * @param array $row
       *
       * @return \Illuminate\Database\Eloquent\Model|null
       */
      public function model(array $row)
      {
          return new Project([
              'chapter_name'     =&gt; $row['chapter_name'],
              'sub_section_name'    =&gt; $row['sub_section_name'],
              'title_1'    =&gt; $row['title_1'],
              'description_1'    =&gt; $row['description_1'],
              'image_1'    =&gt; $row['image_1'],
              'image_2'    =&gt; $row['image_2'],
              'image_3'    =&gt; $row['image_3'],
              'title_2'    =&gt; $row['title_2'],
              'description_2'    =&gt; $row['description_2'],
              'title_3'    =&gt; $row['title_3'],
              'description_3'    =&gt; $row['description_3'],
              'video_1'    =&gt; $row['video_1'],
              'video_2'    =&gt; $row['video_2'],
              'video_3'    =&gt; $row['video_3'],
              'user_id'    =&gt; auth()-&gt;user()-&gt;id,
              'product_id'    =&gt; Product::where('user_id',Auth::id())-&gt;pluck('id')-&gt;last()
          ]);
      }
  }
  </code></pre>
  <p>This is my index.blade.php</p>
  <pre><code>@extends('layouts.app')
  
  @section('content')
  
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-lg-12 margin-tb&quot;&gt;
              &lt;div class=&quot;pull-left&quot;&gt;
                  &lt;h2&gt;Laravel 8 CRUD &lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class=&quot;d-flex flex-row-reverse flex-column&quot;&gt;
                  &lt;div class=&quot;d-flex&quot;&gt;
                      &lt;a class=&quot;btn btn-success text-light mr-5&quot; data-toggle=&quot;medel&quot; id=&quot;mediumButton&quot; data-target=&quot;#mediumModel&quot;
                      data-attr=&quot;{{ route ('projects.create')}}&quot; title=&quot;upload project&quot;&gt;
                          &lt;i class=&quot;fas fa-cloud-upload-alt fa-2x&quot;&gt;&lt;/i&gt;
                      &lt;/a&gt;
                      &lt;form action=&quot;{{ route('importProject') }}&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot; class=&quot;d-flex&quot;&gt;
                          @csrf
                          &lt;input type='file' name=&quot;file&quot;&gt;
  
                          &lt;button class=&quot;btn btn-info&quot; style=&quot;margin-left: -60px&quot; title=&quot;Import Project&quot;&gt;
                              &lt;i class=&quot;fas fa-cloud-upload-alt fa-2x&quot;&gt;&lt;/i&gt;&lt;/button&gt;
  
                              &lt;a class=&quot;btn btn-warning&quot; href=&quot;{{ route('export') }}&quot;&gt;Export User Data&lt;/a&gt;
                      &lt;/form&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;pull-right&quot;&gt;
                  &lt;a class=&quot;btn btn-success text-light&quot; data-toggle=&quot;modal&quot; id=&quot;mediumButton&quot; data-target=&quot;#mediumModal&quot;
                      data-attr=&quot;{{ route('projects.create') }}&quot; title=&quot;Create a project&quot;&gt; &lt;i class=&quot;fas fa-plus-circle&quot;&gt;&lt;/i&gt;
                  &lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      @if ($message = Session::get('success'))
          &lt;div class=&quot;alert alert-success&quot;&gt;
              &lt;p&gt;{{ $message }}&lt;/p&gt;
          &lt;/div&gt;
      @endif
  
      &lt;table class=&quot;table table-bordered table-responsive-lg table-hover&quot;&gt;
          &lt;thead class=&quot;thead-dark&quot;&gt;
              &lt;tr&gt;
                  &lt;th scope=&quot;col&quot;&gt;No&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Chapter Name&lt;/th&gt;
                  &lt;th scope=&quot;col&quot; &gt;Sub-Section Name&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Title 1&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Description 1&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Image 1&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Image 2&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Image 3&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Title 2&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Description 2&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Title 3&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Description 3&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Video 1&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Video 2&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Video 3&lt;/th&gt;
  
                  &lt;th scope=&quot;col&quot;&gt;Date Created&lt;/th&gt;
                  &lt;th scope=&quot;col&quot;&gt;Action&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              @foreach ($projects as $project)
                  &lt;tr&gt;
                      &lt;td scope=&quot;row&quot;&gt;{{ ++$i }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;chapter_name }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;sub_section_name }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;title_1 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;description_1 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;image_1 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;image_2 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;image_3 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;title_2 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;description_2 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;title_3 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;description_3 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;video_1 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;video_2 }}&lt;/td&gt;
                      &lt;td&gt;{{ $project-&gt;video_3 }}&lt;/td&gt;
  
                      &lt;td&gt;{{ date_format($project-&gt;created_at, 'jS M Y') }}&lt;/td&gt;
                      &lt;td&gt;
                          &lt;form action=&quot;{{ route('projects.destroy', $project-&gt;id) }}&quot; method=&quot;POST&quot;&gt;
  
                              &lt;a data-toggle=&quot;modal&quot; id=&quot;smallButton&quot; data-target=&quot;#smallModal&quot;
                                  data-attr=&quot;{{ route('projects.show', $project-&gt;id) }}&quot; title=&quot;show&quot;&gt;
                                  &lt;i class=&quot;fas fa-eye text-success  fa-lg&quot;&gt;&lt;/i&gt;
                              &lt;/a&gt;
  
                              &lt;a class=&quot;text-secondary&quot; data-toggle=&quot;modal&quot; id=&quot;mediumButton&quot; data-target=&quot;#mediumModal&quot;
                                  data-attr=&quot;{{ route('projects.edit', $project-&gt;id) }}&quot;&gt;
                                  &lt;i class=&quot;fas fa-edit text-gray-300&quot;&gt;&lt;/i&gt;
                              &lt;/a&gt;
                              @csrf
                              @method('DELETE')
  
                              &lt;button type=&quot;submit&quot; title=&quot;delete&quot; style=&quot;border: none; background-color:transparent;&quot;&gt;
                                  &lt;i class=&quot;fas fa-trash fa-lg text-danger&quot;&gt;&lt;/i&gt;
                              &lt;/button&gt;
                          &lt;/form&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              @endforeach
          &lt;/tbody&gt;
      &lt;/table&gt;
  
      {!! $projects-&gt;links() !!}
  
  
      &lt;!-- small modal --&gt;
      &lt;div class=&quot;modal fade&quot; id=&quot;smallModal&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot; aria-labelledby=&quot;smallModalLabel&quot;
          aria-hidden=&quot;true&quot;&gt;
          &lt;div class=&quot;modal-dialog modal-sm&quot; role=&quot;document&quot;&gt;
              &lt;div class=&quot;modal-content&quot;&gt;
                  &lt;div class=&quot;modal-header&quot;&gt;
                      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                          &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;modal-body&quot; id=&quot;smallBody&quot;&gt;
                      &lt;div&gt;
                          &lt;!-- the result to be displayed apply here --&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
      &lt;!-- medium modal --&gt;
      &lt;div class=&quot;modal fade&quot; id=&quot;mediumModal&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot; aria-labelledby=&quot;mediumModalLabel&quot;
          aria-hidden=&quot;true&quot;&gt;
          &lt;div class=&quot;modal-dialog&quot; role=&quot;document&quot;&gt;
              &lt;div class=&quot;modal-content&quot;&gt;
                  &lt;div class=&quot;modal-header&quot;&gt;
                      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                          &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;modal-body&quot; id=&quot;mediumBody&quot;&gt;
                      &lt;div&gt;
                          &lt;!-- the result to be displayed apply here --&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
      &lt;script&gt;
          // display a modal (small modal)
          $(document).on('click', '#smallButton', function(event) {
              event.preventDefault();
              let href = $(this).attr('data-attr');
              $.ajax({
                  url: href,
                  beforeSend: function() {
                      $('#loader').show();
                  },
                  // return the result
                  success: function(result) {
                      $('#smallModal').modal(&quot;show&quot;);
                      $('#smallBody').html(result).show();
                  },
                  complete: function() {
                      $('#loader').hide();
                  },
                  error: function(jq
  </code></pre>