I have tried to make a query that brings me all the articles that are in Active but I have not got any results. It always brings me all so the state is inactive and is what I do not want.
These are the questions I have so far:
First query
public function index(Request $request)
{
if ($request) {
/*obtener todos los registro de la base de datos de una determinada articulo
trim:quita espacios*/
$query = trim($request->get('searchText'));
$articulos = Articulo::with(['categoria'])
->where('articulos.estado', '=', 'Activo')
->where('articulos.codigo', 'LIKE', '%' . $query . '%')
->orwhere('articulos.nombre', 'LIKE', '%' . $query . '%')
->orderBy('id', 'desc')
->paginate(2);
return view('bodega.articulo.index', ["articulos" => $articulos, "searchText" => $query]);
}
}
second query
public function index(Request $request)
{
if ($request) {
/*obtener todos los registro de la base de datos de una determinada articulo
trim:quita espacios*/
$query = trim($request->get('searchText'));
$articulos = Articulo::with(['categoria'])
->whereIn('articulos.estado',['Activo'])
->where('articulos.codigo', 'LIKE', '%' . $query . '%')
->orwhere('articulos.nombre', 'LIKE', '%' . $query . '%')
->orderBy('id', 'desc')
->paginate(2);
return view('bodega.articulo.index', ["articulos" => $articulos, "searchText" => $query]);
}
}
The queries have been made in Mysql and they work for me. I also used it with Query Builder de laravel and it worked for me. But I want to know how to consult with Eloquent.