Everything works fine, it's just that the result that was obtained and displayed in the paginate through the search form, and when changing the page in the paginate, everything is lost and the paginate is refilled with all the data.
This is my index in the controller:
public function index(Request $request)
{
if($request)
{
$query = trim($request->get('searchText'));
$locales = DB::table('locales')->where('LocalesNombre','LIKE','%'.$query.'%')
->where('LocalesActivo','=','1')
->orwhere('LocalesTipo','LIKE','%'.$query.'%')
->where('LocalesActivo','=','1')
->orderBy('LocalesCodigo', 'desc')
->paginate(7);
return view('formulario.local.index', ["locales" => $locales, "searchText" => $query]);
}
}
This is my view in index:
@extends ('layouts.admin')
@section ('contenido')
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
<h3>Listado de Locales <a href="/formulario/local/create"><button class="btn btn-success">Nuevo</button></a></h3>
@include('formulario.local.search')
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed table-hover">
<thead>
<th>Id</th>
<th>Nombre</th>
<th>Tipo</th>
<th>Dirección</th>
<th>Teléfono</th>
<th>Encomienda</th>
<th>Pasajes</th>
<th>Color</th>
<th>Opciones</th>
</thead>
@foreach ($locales as $local)
<tr>
<td>{{ $local->LocalesCodigo}}</td>
<td>{{ $local->LocalesNombre}}</td>
<td>{{ $local->LocalesTipo}}</td>
<td>{{ $local->LocalesDireccion}}</td>
<td>{{ $local->LocalesTelefono}}</td>
<td>
@if($local->LocalesEncomienda=='0')
No
@else
Si
@endif
</td>
<td>
@if($local->LocalesPasajes=='0')
No
@else
Si
@endif
</td>
<td>{{ $local->LocalesColor}}</td>
<td>
<a href="{{URL::action('LocalController@edit',$local->LocalesCodigo)}}"><button class="btn btn-info">Editar</button></a>
<a href="" data-target="#modal-delete-{{$local->LocalesCodigo}}" data-toggle="modal"><button class="btn btn-danger">Eliminar</button></a>
</td>
</tr>
@include('formulario.local.modal')
@endforeach
</table>
</div>
{{$locales->render()}}
</div>
</div>
@endsection
In the search form I have this:
{!! Form::open(array('url'=>'formulario/local','method'=>'GET','autocomplete'=>'off','role'=>'search')) !!}
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" name="searchText" placeholder="Buscar..." value="{{$searchText}}">
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">Buscar</button>
<a href="/formulario/local" class="btn btn-default">Listar todo</a>
</span>
</div>
</div>
{{Form::close()}}
Use the appends method before rendering your links. For your example, it would be
Cheers
I would try to change in the view:
by:
Works great, keep going. In my case I use 2 variables: