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

biktorrb's avatar

Filter and Pagination

Hi guys, i make a filter and it works but when i try to access to the second page of the filter response with 404 error

This is my filter function at the controller



public function filtrar(Request $request)
    {

        $reportes = Reporte::whereYear('created_at', '=', $request->input("año"))
                    ->whereMonth('created_at', '=', $request->input("mes"))
                    ->orderBy('created_at', 'asc')
                    ->paginate(8);

        $reporteEmpleados = Reporte::whereYear('created_at', '=', $request->input("año"))
                            ->whereMonth('created_at', '=', $request->input("mes"))
                            ->orderBy('created_at', 'asc')
                            ->paginate(8);

        return view('reportes.filtro', compact('reportes', 'reporteEmpleados'));

    }


And this is my view

@extends('adminlte::page')
@section('htmlheader_title', 'Todos los reportes')
@section('contentheader_title', 'Todos los reportes')
@section('main-content')
<a href="/reportes/create" class="btn btn-success">Redactar un nuevo informe <i class='fa fa-pencil'></i></a>
<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item active" aria-current="page"><b>Filtrar:</b></li>
    <li class="breadcrumb-item active">
      <form action="/reportes/filtro" class="form-inline" method="POST">
        @method('POST')
        @csrf
        <div class="form-group">
          <label for="año">Año</label>
          <select class="form-control" id="año" name="año">
            <option value="2019">2019</option>
            <option value="2020">2020</option>
            <option value="2021">2021</option>
            <option value="2022">2022</option>
            <option value="2023">2023</option>
            <option value="2024">20224</option>
          </select>
        </div>
        <div class="form-group">
          <label for="mes">Mes</label>
          <select class="form-control" id="mes" name="mes">
            <option value="01">Enero</option>
            <option value="02">Febrero</option>
            <option value="03">Marzo</option>
            <option value="04">Abril</option>
            <option value="05">Mayo</option>
            <option value="06">Junio</option>
            <option value="07">Julio</option>
            <option value="08">Agosto</option>
            <option value="09">Septiembre</option>
            <option value="10">Octubre</option>
            <option value="11">Noviembre</option>
            <option value="12">Diciembre</option>
          </select>
        </div>
        <button class="btn btn bg-blue" type="submit">Filtrar</button>
        </form>
    </li>
  </ol>
</nav>
@can('allaccess')
<div class="table-responsive">
<table class="table table-striped text-center" style="margin-top:5px;">
  <thead>
    <tr style="background:#222d32;color:#fff;">
      <th scope="col">#</th>
      <th scope="col">Titulo</th>
      <th scope="col">Autor</th>
      <th scope="col">Fecha y hora de emisión</th>
      <th scope="col">Ver Informe</th>
    </tr>
  </thead>
  <tbody>
    @foreach($reportes as $reporte)
        <tr>
            <td>{{$reporte->id}}</td>
            <td>{{$reporte->titulo}}</td>
            <td>{{$reporte->autor}}</td>
            <td>{{$reporte->created_at}}</td>
    <td><a href="/reportes/{{$reporte->id}}" class="btn btn-primary btn-block">Ver</a></td>
        </tr>
    @endforeach
  </tbody>
</table>
</div>
{{ $reportes->appends('reportes')->links() }}
@endcan
@endsection

I would really appreciate some help

0 likes
4 replies
jlrdw's avatar

Google query string and fully understand how the query string works.

jlrdw's avatar
$query = Dog::where('dogname', 'like', $dogsch);
        if ($aval == "n") {
            $query->where('adopted', '=', 1);
        } else if ($aval == "y") {
            $query->where('adopted', '=', 0);
        }
        $dogs = $query->orderBy('lastedit', 'DESC')->paginate(5);

        $params = array('psch' => $dogsearch, 'aval' => $aval);
        $title = 'Admin';
return view('dog.index', compact('dogs', 'params'))
                        ->with('title', $title);

view:

{{ $dogs->appends($params)->links() }}

Gives

somesite.com/dogs?page=2&psch=b&aval=1

In other words a query string.

Please or to participate in this conversation.