公共属性[samples]的类型必须是:[数值、字符串、数组、null或布尔值]



我正在使用livewire尝试对表进行分页

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);
}
}

我得到这个错误:

LivewireExceptionsPublicPropertyTypeNotAllowedException
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.

我知道变量$this->samples不是一个数字,字符串或数组…但无论如何我需要做分页

我该怎么做呢?

Livewire无法判断paginate函数返回的类型(paginate返回作为IlluminatePaginationLengthAwarePaginator的实例)这是目前不允许的。

一种解决方法可能是删除挂载方法并传递$sample

$samples = Sample::all();
return view('livewire.show', compact('samples'));

相关内容

  • 没有找到相关文章

最新更新