提问者:小点点

装载时发生Laravel livewire分页错误


我试图检索页面挂载上的用户,并使用以下代码对他们进行分页:

public function mount()
{
     $this->users = User::where('register_completed', '1')->paginate(16); 
}

但我有一个错误:

Livewire component's [user-search] public property [users] 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.

计划是使用页面加载中的mount加载所有用户,然后让用户使用具有多个条件的筛选表单对其进行筛选。分页器使用以下代码工作:

public function render()
{
    return view('livewire.user-search', [
            'users' => User::where('register_completed', '1')->paginate(16),
        ])
            ->extends('layouts.app')
            ->section('content');
}

但是我需要使用一个特定的函数来根据所选的条件过滤结果。此外,搜索不是实时的,有一个按钮可以调用搜索过滤器功能。不确定为什么分页仅在通过render方法时有效。另外,$users是从视图访问它的公共属性。


共1个答案

匿名用户

似乎您在Livewire组件中键入了$users属性。正如错误消息所说,除了数值字符串数组布尔之外,您不能向其他内容键入提示公共属性。

请参阅Livewire文档中的重要注释。