0
votes

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.

1
What bug are you referring to? You're still making use of ->paginate() so pagination is to be expected. - Peppermintology
Exactly I need to do a pagination, but just taking it out and putting get () doesn't work. - iLuucasD
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
What is the error you get? What is )-> if ($minParam || $maxParam) supposed to do? - brombeer
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

1 Answers

0
votes

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'));
    
    }