2
I created a filter in my view index, when I put something inside one of the filter inputs enters ifs but I think it’s not good this way, someone knows somehow better?
public function index()
{
$usuariosFiltro = null;
$estadoFiltro = null;
$cidadeFiltro = null;
$statusFiltro = null;
if(Input::has('Usuario_nome'))
{
$usuariosFiltro = Input::get('Usuario_nome');
}
if(Input::has('Usuario_cidade'))
{
$cidadeFiltro = Input::get('Usuario_cidade');
}
if(Input::has('Usuario_status'))
{
$statusFiltro = Input::get('Usuario_status');
}
$usuarios = Usuario::filtrarUsuario($usuariosFiltro)->filtrarCidade($cidadeFiltro)->filtrarStatus($statusFiltro)->paginate();
$estados = Estado::orderBy('uf')->lists('uf', 'est_id');
return view('usuarios.index', compact('usuarios', 'estados'));
}
Post your User and Status models. There are much better ways than your current answer.
– gmsantos
You’re programming an Laravel inside the Laravel.
– Diego Souza
Possible duplicate of Use 'WHERE' if value is different from 'NULL' in a search system
– Wallace Maxters
Another possible duplicate How to Filter Multiple Fields in Query
– Wallace Maxters