NoLAstNamE's avatar

Cursor pagintae GET method Unable to find parameter [created_at]

I'm using Laravel's Cursor paginate to paginate a page that has a Search function with the method of GET. The Search is working fine also the First batch of results are showing, however when I click Next in the paginator I got this error showing Unable to find parameter [created_at] in pagination item.

Controller

if ($request->has('search') && $request->get('search') != '') {
    $user = User::where('username', 'like', $request->get('search').'%')->first();

    if (! $user) {
        $transactions = Transaction::with(['user'])->where('owner_id', Auth::id())->where('code', $request->get('search'))->orderBy('id', 'desc')->cursorPaginate(1);
    } else {
        $transactions = Transaction::with(['user'])->where('owner_id', Auth::id())->where('user_id', $user->id)->orderBy('id', 'desc')->cursorPaginate(1);
    }
} else {
    $transactions = Transaction::with(['user'])->where('owner_id', Auth::id())->orderBy('id', 'desc')->cursorPaginate(1);
}

return view('user.transactions', compact('transactions '));

Blade

<form action="{{ route('transactions.search') }}" method="GET">
    <div class="card-body">
        <div>
            <label for="quantity" class="form-label">Code or Username</label>
            <input type="text" name="search" class="form-control" required>
        </div>
    </div>
    <div class="card-footer">
        <button type="submit" class="btn btn-primary">Search</button>
    </div>
</form>

<table id="lists" class="table table-bordered">
    <thead>
        <tr>
            <th>Status</th>
            <th>Code</th>
            <th>Current Owner</th>
            <th>Date</th>
        </tr>
    </thead>
    <tbody>
        @forelse ($transactions as $item)
            <tr>
                <td>
                    {{ ($item->status }}
                </td>
                <td>{{ $item->code }}</td>
                <td>{{ $item->user->full_name }} ({{ $item->user->username }})</td>
                <td>{{ $item->created_at }}</td>
            </tr>
        @empty
        @endforelse
        {{ $transactions->links() }}
    </tbody>
</table>

If Search is not used, the pagination is working fine.

0 likes
1 reply

Please or to participate in this conversation.