im trying to retrive the users on page mount and paginate them using the following code:
public function mount()
{
$this->users = User::where('register_completed', '1')->paginate(16);
}
but im getting this error:
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.
The plan is to load all of the users using mount
on page load and then let the user filter them using a filter form with multiple criteria. the paginator works using this code:
public function render()
{
return view('livewire.user-search', [
'users' => User::where('register_completed', '1')->paginate(16),
])
->extends('layouts.app')
->section('content');
}
but I need to use a specific function to filter the results based on the selected criteria. also, the search is not real-time and there is a button to call the search filter function.
not sure why pagination only works when passed through the render
method.
also the $users
is a public property to access it from the view.
UserSearch
Livewire component. – codedge<?php namespace App\Http\Livewire; use App\Models\User; use Livewire\Component; use Livewire\WithPagination; class UserSearch extends Component { use WithPagination; protected $paginationTheme = 'bootstrap'; public $search; public $users; public function render() { return view('livewire.user-search') ->extends('layouts.app') ->section('content'); } public function mount() { $this->users = User::where('register_completed', '1')->paginate(16); } }
– Shan