mahipal negi
mahipal negi

Reputation: 317

Laravel Pagination: how to use custom pagination in laravel 5?

I am working on laravel project and I want to use pagination on it,

For Project requirement I used Query like this:-

$result = DB::select("SELECT * FROM table WHERE ".$where." ORDER BY ".$sort." ".$orderBy);

And for pagination

use Illuminate\Pagination\Paginator;

and

Paginator::make($result, sizeof($result), 5);

But it show error

Call to undefined method Illuminate\Pagination\Paginator::make()

and When I used

use Illuminate\Support\Facades\Paginator;

It show error

Class 'Illuminate\Support\Facades\Paginator' not found

Please let me know how to resolve these errors.

Upvotes: 1

Views: 1309

Answers (3)

Jari Pekkala
Jari Pekkala

Reputation: 887

There isn't Paginator facade or make-method in that class.

Instead trying to guess the methods and classes you can check the docs.

$paginated = new \Illuminate\Pagination\LengthAwarePaginator($result, sizeof($result), 5);

By the way all Laravel facades lives in the global namespace so you can import them without specifying the full namespace. Example

use Cache;
use Request;

Upvotes: 0

manoj singh
manoj singh

Reputation: 346

Use Like This working for me

$accounts = User::select('user_id', 'name')->paginate(10)->toArray();

print_r($accounts);

Upvotes: 1

Michel
Michel

Reputation: 1165

$result = YourModel::where('condition', $value)->orderBy('columnName', 'DESC')->paginate(5);

return view('yourview', ['data', $result]);

In your view

@foreach($data as $result)
{{$result->tableColumnHere}}
@endforeach

//This will print the pagination links
{{$data->links()}}

Upvotes: 0

Related Questions