To paginate the table with values from API, you can use Laravel's built-in pagination feature. Here's how you can modify the code to achieve this:
- First, you need to fetch the data from the API and store it in a variable. You can do this in your controller method like this:
public function index()
{
$values = // fetch data from API
return view('your-view', compact('values'));
}
- Next, you can use Laravel's
paginatemethod to paginate the data. Modify your controller method like this:
public function index()
{
$values = // fetch data from API
$values = collect($values->bonuses)->paginate(7);
return view('your-view', compact('values'));
}
Here, we're using the collect method to convert the data into a collection, and then calling the paginate method on it to paginate the data with 7 items per page.
- In your view, you can loop through the paginated data like this:
@foreach ($values as $value)
<div class="row list-item">
<div class="col-4">
<h4 class="mb-0 font-d-bld text-white">{{ $loop->iteration }}) {{ $value->name }}</h4>
</div>
<div class="col-2">
<h4 class="mb-0 font-d-bld text-white">{{ $value->bet_size }}</h4>
</div>
<div class="col-3">
<h4 class="mb-0 font-d-bld text-white">{{ $value->multiplier }}</h4>
</div>
<div class="col-3">
<h4 class="mb-0 font-d-bld text-white">{{ $value->payout }}</h4>
</div>
</div>
@endforeach
Here, we're using the @foreach directive to loop through the paginated data, and the $loop->iteration variable to display the item number.
- Finally, you can use Laravel's built-in pagination links to display the pagination buttons. Replace the pagination section in your view with this:
{{ $values->links() }}
This will display the pagination links with the default styling. If you want to customize the styling, you can use the links method with a custom view like this:
{{ $values->links('your-custom-pagination-view') }}
Here, your-custom-pagination-view is the name of your custom pagination view file. You can create this file in the resources/views/vendor/pagination directory and customize the pagination links as per your requirements.