Level 1
Controller function
$horarios = horarios::filtro($request->get('filtro'))->orderBy('id', 'DESC')->paginate(20);
return view('crud.CRUDFechasYHorarios.CRUDFechasYHorariosIndex',compact('horarios'));
dd($horarios);
Hello guys, i've been having a problem with the pagination, i have a schedule table(ferry trips) and i add it a "search - filter" button, i have it with pagination of 20, and i have a route(different schedules in different routes) with over 60 register, so with i filter to get that info i only get it to display correct the first page, but when i clic on the second page it goes to the full table and data.
This is my code
Scope function in model
static function scopeFiltro($query, $filtro)
{
$rutas=config('options.ruta');
if($filtro != "" && isset($rutas[$filtro]))
{
$query->where('Ruta', $filtro);
}
}
config file
return array(
'ruta' =>[
'' => 'Seleccione una ruta',
'Playa del Carmen - Cozumel-1' => 'Playa del Carmen - Cozumel-1',
'Playa del Carmen - Cozumel-2' => 'Playa del Carmen - Cozumel-2',
'Puerto Juarez - Isla Mujeres' => 'Puerto Juarez - Isla Mujeres',
'Playa Tortugas - Isla Mujeres' => 'Playa Tortugas - Isla Mujeres',
'El embarcadero - Isla Mujeres' => 'El embarcadero - Isla Mujeres',
'Playa Caracol - Isla Mujeres' => 'Playa Caracol - Isla Mujeres'
]
);
View file
<?php use App\Http\Controllers\crudHorariosController; ?>
{{-- Extends/Includes --}}
@extends('layouts.Admin.admin')
{{-- Variables de estructura --}}
@section('pageId', 'admin')
@section('pageCls', 'dashboard')
{{-- Variables de pagina --}}
@section('meta_title', 'Horarios')
{{-- Estructura HTML --}}
@section('content')
<div class="pull-left">
<h2>Lista de horarios</h2>
</div>
<div class="clearfix"></div>
<div class="panel panel-default">
<div class="panel-heading">
<div class="act-btn vertical-center">
{!! Form::open(array('route' => 'admHorario.index','method'=>'GET', 'class' => 'search-form act-btn-btn mh-20px', 'role' => 'search')) !!}
{!! Form::select('filtro',config('options.ruta'), NULL, ['class' => 'form-control']) !!}<div class="mh-5px"></div>
<button type="submit" class="btn btn-info">Filtrar</button>
{!! Form::close() !!}
{!! Form::open(array('route' => 'admultramar.store', 'class' => ' act-btn-btn mh-20px')) !!}
{!! Form::hidden('message', 'horarios') !!}
{!! Form::submit('Crear', ['class' => 'btn btn-block btn-success']) !!}
{!! Form::close() !!}
<a class="btn btn-primary act-btn-btn mh-20px" href="{{ route('admultramar.index') }}"> Volver</a>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
@if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
@endif
<div class="table-responsive">
<table class="table table-striped table-bordered">
<tr>
<th>No</th>
<th>Ruta</th>
<th>Hora Ida</th>
<th>Hora Regreso</th>
<th>Estatus</th>
<th>Action</th>
</tr>
@foreach ($horarios as $key => $item)
<tr>
<td>{{ $item->id }}</td>
<td>{{ $item->Ruta }}</td>
<td>{{ $item->HSalidaHora }}:{{ $item->HSalidaMinuto}}<?php if( $item->HSalidaMinuto < 10) echo '0'?> {{ $item->HSalidaAP}}</td>
<td>{{ $item->HRegresoHora }}:{{ $item->HRegresoMinuto}}<?php if( $item->HRegresoMinuto < 10) echo '0'?> {{ $item->HRegresoAP}}</td>
<td>{{ $item->Status }}</td>
<td>
<div class="act-btn">
<a class="btn btn-warning mh-10px" href="{{ route('admHorario.edit',$item->id) }}">Editar</a>
{!! Form::open(['method' => 'DELETE','route' => ['admHorario.destroy', $item->id]]) !!}
{!! Form::submit('Eliminar', ['class' => 'btn btn-danger mh-10px']) !!}
{!! Form::close() !!}
</div>
</td>
</tr>
@endforeach
</table>
</div>
{!! $horarios->render() !!}
</div>
</div>
@endsection
Dont know what could be
{{ $horarios->appends(request()->only(['filtro']))->render() }}
Please or to participate in this conversation.