0

I am using livewire trying to paginate the table

   public function mount($lab = null)
{
    $this->sample = new Sample;

    if ($lab) {
        $this->lab = Lab::find($lab);
        $this->samples = Sample::whereLabId($this->lab->id)->paginate(5);

    }
}

I got this error:

    Livewire\Exceptions\PublicPropertyTypeNotAllowedException
Livewire component's [sample-data] public property [samples] must be of type: [numeric, string, array, null, or boolean]. Only protected or private properties can be set as other types because JavaScript doesn't need to access them.

I know that the variable $this->samples is an instant not a numeric, string or array... but eventhow I need to do the pagination

How can I do that?

Zahraa
  • 67
  • 7

1 Answers1

0

Livewire can not figure out type the paginate function returns (paginate returns as instance of Illuminate\Pagination\LengthAwarePaginator) and that is not allowed at the moment .

A work around might be to remove the mount method and pass the $sample with compact as shown below .

$samples = Sample::all();

return view('livewire.show', compact('samples'));
helvete
  • 2,455
  • 13
  • 33
  • 37