What I want to do is a table like this that is painted in excel with a query in eloquent de laravel what happens is that I already try several codes without success the only one that works is the one that I put in the post but only for the sql editor in my case I have it in xampp
This is the database I'm using link
this is the code that worked for me but only as a query in the terminal of xampp but it does not work in eloquent laravel I get an error when wanting to paint them in the html window by means of a foreach
public function __construct(){
}
public function index(Request $request){
if ($request){
$query=trim($request->get('searchText'));
$material=DB::select(db::raw("SELECT vtm.fecha fecha,
(SELECT SUM(vtm2.cantidadMaterial) FROM vehiculo_transporte_material vtm2
WHERE vtm.fecha=vtm2.fecha AND vtm2.idMaterial=1) AS arena,
(SELECT SUM(vtm2.cantidadMaterial) FROM vehiculo_transporte_material vtm2
WHERE vtm.fecha=vtm2.fecha AND vtm2.idMaterial=2) AS base,
(SELECT SUM(vtm2.cantidadMaterial) FROM vehiculo_transporte_material vtm2
WHERE vtm.fecha=vtm2.fecha AND vtm2.idMaterial=3) AS Subbase,
(SELECT SUM(vtm2.cantidadMaterial) FROM vehiculo_transporte_material vtm2
WHERE vtm.fecha=vtm2.fecha AND vtm2.idMaterial=4) AS filtrante,
FROM vehiculo_transporte_material as vtm
GROUP BY vtm.fecha"));
return view('traza.materiales.indexProduccion',
["material"=>$material,"searchText"=>$query]);
}
}