Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 6, 2020 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/7b514439f42c479a7a13740dbfd2f239 to your computer and use it in GitHub Desktop.
Save parzibyte/7b514439f42c479a7a13740dbfd2f239 to your computer and use it in GitHub Desktop.
<?php
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$ventasConTotales = Venta::join("productos_vendidos", "productos_vendidos.id_venta", "=", "ventas.id")
->select("ventas.*", DB::raw("sum(productos_vendidos.cantidad * productos_vendidos.precio) as total"))
->groupBy("ventas.id", "ventas.created_at", "ventas.updated_at")
->get();
return view("ventas.ventas_index", ["ventas" => $ventasConTotales,]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment