I'm using guzzle to make a get request. My response look like this:
{"current_page":1,
"data":[
{"name1":"Example Name", "name2":"Additional Example Name", "Street":"ExampleStreet", "Country":"DE", "ZIP":"4800", "Place":"ExamplePlace"},
{"name1":"Example Name1", "name2":"Additional Example Name1", "Street":"ExampleStreet2", "Country":"AT", "ZIP":"3863", "Place":"ExamplePlace1"},
.
.
.
.
],
"first_page_url": "http://localhost:8080/api/address?page=1",
"from": 1,
"last_page": 15,
"last_page_url": "http://localhost:8080/api/address?page=15",
"next_page_url": "http://localhost:8080/api/address?page=2",
"path": "http://localhost:8080/api/address",
"per_page": 500,
"prev_page_url": null,
"to": 500,
"total": 7315
}
I'm getting the data to m view:
@foreach($addressesData as $address)
<tr>
<td>x</td>
<td>x</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
@endforeach
and this is my controller:
class AddressController extends Controller
{
public function index()
{
$http = new \GuzzleHttp\Client;
$res = $http->request('GET', 'http://localhost:8080/api/address');
$addresses = json_decode((string) $res->getBody(), true)['data'];
return view('address.index', compact('addresses'));
}
}
Now i would like to add the pages links. What is the best way to achive this ? Do i have to add so many variables( for example: first_page_url, from, last_page,... ) to compact function ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire