Hey there,
I’m using Livewire for the second time now. I’m also using an API that I call throught Http from Laravel.
The api works with pages that means that when you make a request the request url ends with ?page=1
.
This means depending on which page you’re loading, the right data will be loaded (10 items). And it will also send you the previous/next links (in case you’re on the first or last page it returns to prevent going to non existent pages) to make a navigation for the api data. It works when I click on next everytime, but when I go back, at a random moment, differs from page 4 to page 3
or page 3 to page 2
it will give the error Undefined index: links
. I’ve already tried some livewire lifecycle hooks to see what happens when it’s updating the component or whatsoever, but none of them worked for me.
Here’s the code in my current situation:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Support\Facades\Http;
class DomainList extends Component
{
public $base_url = www.'api.com/site?page=1';
// public $page_number = 1;
public $domains;
public $first_page;
public $last_page;
public $prev;
public $next;
public function mount(){
$this->update_data();
}
public function increment(){
if($this->next){
$this->base_url = $this->next;
}
$this->update_data();
}
public function decrement(){
if($this->prev){
$this->base_url = $this->prev;
}
$this->update_data();
}
public function update_data(){
$response = Http::withOptions([ //use this method
'verify' => false, //This key and value in this method
])->withHeaders([
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer '.env('GRIDPANE_BEARER_TOKEN'),
'data-raw' => [
'summary' => true,
],
])->get($this->base_url);
$this->next = $response['links']['next'];
$this->prev = $response['links']['prev'];
$this->domains = collect($response['data'])->map(fn($domain) => (object) $domain);
}
public function updating($base_url){
dd('test');
}
public function render()
{
return view('livewire.domain-list')->extends('layouts.app');
}
}
As you can see I’ve tried updating
, but that doesn’t do anything.