0

I need to remove the pagination and leave everything on one page, but this way I'm doing it only generates BUG. I wonder why the snippet of the commented code doesn't work to remove the pagination.

if ($minParam || $maxParam) {
  $products = Product::whereHas('sizes', function ($query) use ($minParam, $maxParam) {
    if ($minParam && $maxParam) {
      $query->whereBetween('max_capacity', [$minParam, $maxParam]);
    } elseif ($minParam) {
      $query->where('max_capacity', '>=', $minParam);
    } else {
      $query->where('max_capacity', '<=', $maxParam);
    }
  })
    ->whereHas('solutions', function ($query) use ($solution_id) {
      $query->whereIn('solution_id', $solution_id);
    })
    ->where('active', 1)
    ->orderBy('position', 'ASC')
    ->get();
  //->paginate(16);
} else {
  $products = Product::whereHas('solutions', function ($query) use ($solution_id) {
    $query->whereIn('solution_id', $solution_id);
  })
    ->where('active', 1)
    ->orderBy('position', 'ASC')
    ->get();
  //->paginate(16);
}
return view('solutions.show')->with(compact('solutions', 'solution', 'products', 'ranges'));

} }

The bug after replacing with get ()

ErrorException (E_ERROR) Method Illuminate\Database\Eloquent\Collection::links does not exist. (View: /app/server/resources/views/solutions/show.blade.php) Previous exceptions Method Illuminate\Database\Eloquent\Collection::links does not exist.

iLuucasD
  • 1
  • 2
  • 2
    What `bug` are you referring to? You're still making use of `->paginate()` so pagination is to be expected. – Peppermintology Oct 23 '20 at 13:00
  • Exactly I need to do a pagination, but just taking it out and putting get () doesn't work. – iLuucasD Oct 23 '20 at 13:20
  • You do need pagination, or don't need pagination? You've still not told us what the error message you're getting is. That would probably help. – Peppermintology Oct 23 '20 at 13:24
  • What is the error you get? What is `)-> if ($minParam || $maxParam)` supposed to do? – brombeer Oct 23 '20 at 13:24
  • I want Remove pagination. I dont´t need pagination. posted error. – iLuucasD Oct 23 '20 at 13:28
  • You posted the code from the vendor directory that throws an error. What is the **exact error message** that it's throwing? Also, show us the code where you've replaced `paginate` with `get` – aynber Oct 23 '20 at 13:54
  • 1
    `Collection::links` on `show.blade.php` <-- Your `show` view is still using the pagination links. Find that and take it out. The issue is not from the code you're showing here. – aynber Oct 23 '20 at 14:15
  • Understand. I found show.blade.php, now I'm going to look for where to change, the truth is that I don't know what to change hahahah – iLuucasD Oct 23 '20 at 17:05

1 Answers1

0

try changing ->paginate(16) to ->get() in all of the code like this:

    whereHas('sizes', function($query)  use($minParam, $maxParam) {
         if($minParam && $maxParam) {
             $query->whereBetween('max_capacity', [$minParam, $maxParam]);
         } elseif($minParam) {
             $query->where('max_capacity', '>=', $minParam);
         } else {
             $query->where('max_capacity', '<=', $maxParam);
         }
     })->
    
    if ($minParam || $maxParam) {
      $products = Product::whereHas('sizes', function ($query) use ($minParam, $maxParam) {
        if ($minParam && $maxParam) {
          $query->whereBetween('max_capacity', [$minParam, $maxParam]);
        } elseif ($minParam) {
          $query->where('max_capacity', '>=', $minParam);
        } else {
          $query->where('max_capacity', '<=', $maxParam);
        }
      })
        ->whereHas('solutions', function ($query) use ($solution_id) {
          $query->whereIn('solution_id', $solution_id);
        })
        ->where('active', 1)
        ->orderBy('position', 'ASC')
        ->get();
    } else {
      $products = Product::whereHas('solutions', function ($query) use ($solution_id) {
        $query->whereIn('solution_id', $solution_id);
      })
        ->where('active', 1)
        ->orderBy('position', 'ASC')
        ->get();

 /*$products = Product::whereHas('solutions', function ($query) use ($solution_id) {
    $query->whereIn('solution_id', $solution_id);
  })
    ->where('active', 1)
    ->orderBy('position', 'ASC');*/
    
      return view('solutions.show')->with(compact('solutions', 'solution', 'products', 'ranges'));
    
    }
Babak Asadzadeh
  • 1,207
  • 1
  • 11
  • 21
  • I changed -> paginate (16) to -> get () throughout the code, but the error persists. Do not place items on a single page. – iLuucasD Oct 23 '20 at 13:14
  • 1
    @iLuucasD edit your question and show us the error you are getting. – ArJay Oct 23 '20 at 13:16