user15740285
user15740285

Reputation: 1

Pagination with condition from form in laravel

I want to make pagination with condition from form in laravel. but when I click page 2, there's nothing in there. the sketch is like this

pagination page 1

pagination page 2

my code in controller is like this

 public function search(Request $request){

    if($request->emotion=="all"){
        $data = Dataset::select('*')->where([
            ['category', '=', $request->category]    
        ])->paginate(15);
    }
    else{
        $data = Dataset::select('*')->where([
            ['category', '=', $request->category],
            ['label', '=', $request->emotion]    
        ])->paginate(15);
    }

    return view('dataset.search', [
        'data' => $data,
        'label' => $request->emotion
    ]);
}

and in route is like this

Route::post('/dataset-detail', [DatasetController::class, 'search']);
Route::get('/dataset-detail', [DatasetController::class, 'search']);

and in view like this

<tbody>
                                @if($data==NULL)
                                <td colspan="8">NO DATA FOUND IN HERE !</td>
                                @else
                                    @foreach ($data as $datas)
                                    <tr>
                                        <td>{{ $loop->iteration }}</td>
                                        <td>{{ $datas->tweet }}</td>
                                        <td>{{ $datas->text_processing }}</td>
                                        <td>{{ $datas->akurasi_naive }}</td>
                                        <td>{{ $datas->akurasi_svm }}</td>
                                        <td>{{ $datas->akurasi_knn }}</td>
                                        <td><a class="btn btn-primary">{{ $datas->label }}</a></td>
                                        @if($datas->category=="train_test")
                                            <td>Training and Testing</td>
                                        @else
                                            <td>Validation</td>
                                        @endif
                                    </tr>
                                    @endforeach
                                @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div align="center">
            <table>
                <tr>
                    <th>{{ $data->links() }}</th>
                </tr>
            </table>

how to make the paginate works with condition that I input before in form like in function search ?

Upvotes: 0

Views: 921

Answers (1)

add to your code with this :

->paginate(15)->withQueryString();

Upvotes: 4

Related Questions