charlieBrown's avatar

How to add a button filter to filter results from pagination

I would like to add a button to filter the results returned by paginate. I have been looking into the documentation but I'm not beeing able to use the docummentation's example to my case.

<table class="table">
        <thead>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Link para perfil</th>
            <th>Avaliação Profissao</th>
            <th>Raio deslocacao</th>
            <th>Preco/Hora</th>
            <th style="width: 36px;"></th>
        </tr>
        </thead>
        <tbody>
        @foreach($profissoesUser as $profissaoUser)
            <tr>
                <td>{{ $profissaoUser->users->name }}</td>
                <td>{{ $profissaoUser->users->last_name }}</td>
                <td><a href="{{ URL::to('/users/')}}/{{$profissaoUser->users->userProfile}}">Visitar Perfil</a> </td>
                <td>{{ $profissaoUser->stars }}</td>
                <td>{{ $profissaoUser->raio_deslocacao }}</td>
                <td>{{ $profissaoUser->preco_hora }}€/h</td>
            </tr>
        @endforeach
        </tbody>
    </table>

<div class="pagination text-center">
    {{ $profissoesUser->links() }}
</div>

Search Model

if($request->has('orderBy')){
                //I only have two filters by now. That's why the if/else
                if($request->get('orderBy') == "stars"){
                    $profissoesUser = ProfissaoUser::where([
                        ['distrito_id', '=', $distritoID->id],
                        ['profissao_id', '=', $profissaoID->id]
                    ])->orderBy($request->get('orderBy'), 'desc')->simplePaginate(2);
                }else{
                    $profissoesUser = ProfissaoUser::where([
                        ['distrito_id', '=', $distritoID->id],
                        ['profissao_id', '=', $profissaoID->id]
                    ])->orderBy($request->get('orderBy'), 'asc')->simplePaginate(2);
                }
}else{
                $profissoesUser = ProfissaoUser::where([
                    ['distrito_id', '=', $distritoID->id],
                    ['profissao_id', '=', $profissaoID->id]
                ])->simplePaginate(2);
          }
}

I know I can use appends() to append a sort of filter to my URI but how do I do that? Do I check if the button is pressed if it's pressed I will apends()?

0 likes
0 replies

Please or to participate in this conversation.