Problems showing items in laravel 5.0

-1

I'm making this query

$ventas = VentasProductos::select('id_factura','=' ,$id);

to a database table from a FacturaController Controller and when I check the number of elements, it returns me that there are elements but at the time of showing them in a view it does not return values to me. How can I solve this?

    
asked by albertolg89 19.03.2018 в 13:44
source

2 answers

1

The query to use an Eloquent would be:

$ventas = VentasProductos::where('id_factura',$id)->get();

That would be a query to the model you made. It is not select since that is used to specify fields of the model you created.

Now you have to have the imported model in the Controller that you created to work as well. But if that is not the case you can use DB of Query Builder that I do not recommend but it is used for queries that do not use models created in your project.

$ventas = DB::select('select * from nombreTabla where id_factura =:id', ['id' => $id]);
    
answered by 19.03.2018 / 13:47
source
1

Your query is fine but it is incomplete, that is to say once you execute these operations you have to indicate with another method that returns the results, in this case as you are doing a query with a filter at the end you must have access to the method get ();

then it should be:

$ventas = VentasProductos::where('id_factura','=' ,$id)->get();
    
answered by 19.03.2018 в 14:03