Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SolomonRei's avatar

Filtering with Pagination

I've stumbled upon some troubles. I have 3 tables and have to make pagination fore each. But I get my data one request

Controller

  if(\App\User::where('id', Auth::id())->first()->group_store == 'admin') $data = Proposal::all();
        else $data = Proposal::where('user_id', Auth::id())->get();

        $new = $data->filter(function ($item) {
            if ($item->state == 'new') return $item;
        })->values();

        $paid = $data->filter(function ($item) {
            if ($item->state == 'paid') return $item;
        })->values();

        $error = $data->filter(function ($item) {
            if ($item->state == 'error') return $item;
        })->values();

        return view('dashboard.proposal')->with([
            'proposals_paid' => $paid,
            'proposals_new' => $new,
            'proposals_error' => $error,
            'menu' => \App\User::where('id', Auth::id())->get(),
        ]);

Blade

@section('content')
    <div class="container">
        <p style="color: #FFFFFF">For Checking</p>
        <table class="table" style="background: white">
            <thead class="thead-light">
            <tr>
                <th scope="col">Status</th>
                <th scope="col">#</th>
                <th scope="col">Payment System</th>
                <th scope="col">Sender</th>
                <th scope="col">Recipient</th>
                <th scope="col">Amount, $</th>
                <th scope="col">Date</th>
                <th scope="col"></th>
            </tr>
            </thead>
            <tbody>
            @foreach($proposals_error as $p)
                <tr>
                    <th scope="row">{{ $p->status_full }}</th>
                    <td>{{ $p->id }}</td>
                    <td>{{ $p->payment_system }}</td>
                    <td>{{ $p->sender }}</td>
                    <td>{{ $p->recipient }}</td>
                    <td>{{ $p->amount }}</td>
                    <td>{{ date('d M, Y H:i', strtotime($p->created_at)) }}</td>
                    <td>
                        <a href="" class="btn btn-danger">Change price</a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    <div class="container">
        <p style="color: #FFFFFF">New</p>
        <table class="table" style="background: white">
            <thead class="thead-light">
            <tr>
                <th scope="col">Status</th>
                <th scope="col">#</th>
                <th scope="col">Payment System</th>
                <th scope="col">Sender</th>
                <th scope="col">Recipient</th>
                <th scope="col">Amount, $</th>
                <th scope="col">Date</th>
                <th scope="col"></th>
            </tr>
            </thead>
            <tbody>
            @foreach($proposals_new as $p)
                <tr>
                    <th scope="row">{{ $p->status_full }}</th>
                    <td>{{ $p->id }}</td>
                    <td>{{ $p->payment_system }}</td>
                    <td>{{ $p->sender }}</td>
                    <td>{{ $p->recipient }}</td>
                    <td>{{ $p->amount }}</td>
                    <td>{{ date('d M, Y H:i', strtotime($p->created_at)) }}</td>
                    <td>
                        <a href="" class="btn btn-danger">Change price</a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>

    <div class="container">
        <p style="color: #FFFFFF">Awaiting</p>
        <table class="table" style="background: white">
            <thead class="thead-light">
            <tr>
                 <th scope="col">Status</th>
                <th scope="col">#</th>
                <th scope="col">Payment System</th>
                <th scope="col">Sender</th>
                <th scope="col">Recipient</th>
                <th scope="col">Amount, $</th>
                <th scope="col">Date</th>
                <th scope="col"></th>
            </tr>
            </thead>
            <tbody>
            @foreach($proposals_paid as $p)
                <tr>
                    <th scope="row">{{ $p->status_full }}</th>
                    <td>{{ $p->id }}</td>
                    <td>{{ $p->payment_system }}</td>
                    <td>{{ $p->sender }}</td>
                    <td>{{ $p->recipient }}</td>
                    <td>{{ $p->amount }}</td>
                    <td>{{ date('d M, Y H:i', strtotime($p->created_at)) }}</td>
                    <td>
                        <a href="" class="btn btn-danger">Change price</a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
@endsection

How can i make pagination for each table. Thanks!

0 likes
1 reply

Please or to participate in this conversation.