Cursor pagination in Laravel requires the use of a unique, sequentially ordered column to paginate through the results efficiently. The error you're encountering, "Illegal operator and value combination," is likely due to the fact that cursor pagination cannot be used with non-sequential ordering or with the orWhere conditions that you have in your query.
To resolve this issue, you should ensure that you're using a single column to order your results that is guaranteed to be unique and sequential. In most cases, this would be the primary key of the table, such as id. If you need to support searching, you'll have to use a different pagination method, such as simplePaginate or paginate, which do not have the same constraints as cursorPaginate.
Here's how you can modify your getItems method to use standard pagination:
class Index extends Component
{
use WithPagination;
public $query = '';
public function getItems()
{
return Student::select(['id', 'firstname', 'lastname', 'midname', 'email', 'phone'])
->when(
$this->query,
function ($query, $search) {
$query->where('lastname', 'ilike', "%$search%")
->orWhere('firstname', 'ilike', "%$search%")
->orWhere('midname', 'ilike', "%$search%");
}
)
->orderBy('lastname', 'asc')
->orderBy('firstname', 'asc')
->orderBy('midname', 'asc')
->paginate(10); // Adjust the number of items per page as needed
}
// ...
}
Please note that I've moved the orderBy clauses after the when clause to ensure that the search conditions are applied first, and then the results are ordered. Also, I've changed cursorPaginate(1) to paginate(10), which will paginate the results with 10 items per page. Adjust the number of items per page according to your needs.
Remember that with standard pagination, you can still use the {{ $items->links() }} in your Blade template to render the pagination links. Cursor pagination does not support the links() method because it works differently and is designed for API usage where you typically only need the next cursor link.