Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use paginate after using switch. - Laravel

I want to use the switch before using paginate. But am getting this error in my view -

Call to undefined method Illuminate\Database\Eloquent\Builder::links().

My Code - MyController.php

$var = User::select('somefield', 'anotherfield');

switch($condition){
   case foo:
       $var->where('bar', '=', 'xyz');
   break;
   case etc:
       $var->where('bar', '=', 'abc')
   break;
}
$var->paginate(10);
return View::make('x.y.z', compact('var'));
like image 753
Piyush Avatar asked Dec 09 '25 12:12

Piyush


1 Answers

You need to catch in some variable as,

$data = $var->paginate(10);
return View::make('x.y.z', compact('data'));

In your current code, you are not saving paginated result anywhere.

like image 101
Rahul Avatar answered Dec 12 '25 01:12

Rahul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!