我试图在laravel中创建一个具有两个日期选择的过滤器,它可以工作,但是当我尝试访问过滤器的第二页时,出现了404错误。
我一直在尝试使用查询中的两个字段进行过滤,并且可以正常工作,但是当我尝试进入过滤器页面时,出现404错误。
这是我在控制器上的过滤功能
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(15);
return view('reportes.filtro', compact('reportes'));
}
这是我的观点
@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->render() }}
@endcan
@if(session('reporteCreado'))
<button type="button" class="close" data-dismiss="alert">×</button>
<div class="alert alert-success" role="alert">
{{session('reporteCreado')}}
</div>
@endif
@if(session('reporteEliminado'))
<button class="close" type="button" data-dismiss="alert">×</button>
<div class="alert alert-danger" role="danger">
{{session('reporteEliminado')}}
</div>
@endif
@endsection
现在过滤器可以工作了,但是我不能正确使用分页。我希望你们能帮助我