I have a search engine in laravel for teams by its ip and by its bar code for that create two scopes
public function scopeBuscarip($query, $ip)
{
if (trim($ip) != '') {
$query = $query->where('ip', $ip);
}
}
public function scopeBuscarcod($query, $ip)
{
if (trim($ip) != '') {
$query = $query->where('cod_barra', $ip);
}
}
This works well, but when I do not have registered products, it creates a redirection loop that is my problem. Someone can help me with this validation.
this is my code in the controller
public function index(Request $request)
{
$equipos = Equipo::buscarip($request->ip)->orderBy('id', 'ASC')->paginate(10);
if (count($equipos) == null) {
$equipos = Equipo::buscarcod($request->ip)->orderBy('id', 'ASC')->paginate(10);
if (count($equipos) == null) {
flash('No existe equipo registrado con la IP o el Codigo de Barra: ' . $request->ip , 'danger');
return redirect()->route('equipos.index');
}else{
return view('equipos.list')->with('equipos', $equipos);
}
}else{
return view('equipos.list')->with('equipos', $equipos);
}
}