"pagination in api laravel" Code Answer's
You're definitely familiar with the best coding language PHP that developers use to develop their projects and they get all their queries like "pagination in api laravel" answered properly. Developers are finding an appropriate answer about pagination in api laravel related to the PHP coding language. By visiting this online portal developers get answers concerning PHP codes question like pagination in api laravel. Enter your desired code related query in the search bar and get every piece of information about PHP code related question on pagination in api laravel.
create custom pagination in laravel 7 for api
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class PaginationController extends Controller
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$myArray = [
['id'=>1, 'title'=>'Laravel 6 CRUD'],
['id'=>2, 'title'=>'Laravel 6 Ajax CRUD'],
['id'=>3, 'title'=>'Laravel 6 CORS Middleware'],
['id'=>4, 'title'=>'Laravel 6 Autocomplete'],
['id'=>5, 'title'=>'Laravel 6 Image Upload'],
['id'=>6, 'title'=>'Laravel 6 Ajax Request'],
['id'=>7, 'title'=>'Laravel 6 Multiple Image Upload'],
['id'=>8, 'title'=>'Laravel 6 Ckeditor'],
['id'=>9, 'title'=>'Laravel 6 Rest API'],
['id'=>10, 'title'=>'Laravel 6 Pagination'],
];
$myCollectionObj = collect($myArray);
$data = $this->paginate($myCollectionObj);
return view('paginate', compact('data'));
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function paginate($items, $perPage = 5, $page = null, $options = [])
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
}
# Blade file
<div class="container">
<table class="table table-bordered">
<tr>
<th>Id</th>
<th>Title</th>
</tr>
@foreach($data as $post)
<tr>
<td>{{ $post->id }}</td>
<td>{{ $post->title }}</td>
</tr>
@endforeach
</table>
</div>
{{ $data->links() }}
pagination in api laravel
follow this link
https://github.com/spatie/laravel-json-api-paginate
All those coders who are working on the PHP based application and are stuck on pagination in api laravel can get a collection of related answers to their query. Programmers need to enter their query on pagination in api laravel related to PHP code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about pagination in api laravel for the programmers working on PHP code while coding their module. Coders are also allowed to rectify already present answers of pagination in api laravel while working on the PHP language code. Developers can add up suggestions if they deem fit any other answer relating to "pagination in api laravel". Visit this developer's friendly online web community, CodeProZone, and get your queries like pagination in api laravel resolved professionally and stay updated to the latest PHP updates.