nhayder
3 months ago

can't paginate search result records?

Posted 3 months ago by nhayder

this is the form

<form action="{{route('rp')}}" method="GET" role="search" enctype="multipart/form-data">
    @csrf
    <input type="text" name="search" class="search-input form-control" placeholder="@lang('translation.search')" required="true"/>

</form>

and i have this route to execute the search

Route::get('/rp', '[email protected]')->name('rp');

in my controller


    public function resultPage(Request $request)
    {


        $request->validate([

            'search' => 'required|string|min:3',

        ]);
        

        $query = User::query();

        $columns = ['firstname','familyname', 'email', 'language', 'adminnote','gender','address1','address2','company','city','postalcode','phone'];

        foreach($columns as $column){

            $query->orWhere($column, 'LIKE', '%' . $request->search . '%');
        }

        $results = $query->paginate(25);

        return view('admin.search', compact('results'));
        
    }

at the same time i'm using links() function to paginate results


@foreach($results as $user)
    
    // do something

@endif

{{ $results->links() }}

this is what i'm getting on the browser when submitting search from


http://127.0.0.1:8000/en/admin/rp?_token=YDZrO7i6h0ao7OSokwmttqL8YoONFNqf6z9pn9Cq&search=johan

when hover over the pagination button i'm getting these


http://127.0.0.1:8000/en/admin/rp?page=2 // and page=3 + 5 + 10  etc

the problem is that pationation is not working it basically stays on same page even after i click the next button

what seems to be the problem

?????

Please sign in or create an account to participate in this conversation.