I have a question to make a query where I show the sale with your items sold.
I currently have this query:
$query=trim($request->get('serachText'));
$ventas=DB::table('venta as v')
->join('persona as p', 'v.cliente','=','p.idpersona')
->join('detalle_venta as dv','v.idventa','=','dv.venta')
->join('articulo as a','dv.articulo','=',"a.idarticulo")
->select('v.idventa','v.fecha_hora','p.nombre','v.tipo_comprobante','v.serie_comprobante','v.num_comprobante','v.impuesto','v.estado', 'v.total_venta','a.nombre')
->where('v.num_comprobante','LIKE', '%'.$query.'%')
->orderBy('v.idventa','desc')
->paginate(7);
return view('ventas.venta.index',["ventas"=>$ventas,"searchText"=>$query]);
With the previous query it shows me the sales but if for example I have a sale of a client with several articles I repeat the information, as I show in the image:
This is the relational database:
finally this is the code of the view:
@extends('layoust.admin')
@section ('contenido')
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
<h3>
Listado de Ventas
<a href="venta/create">
<button class="btn btn-success">
Nuevo
</button>
</a>
</h3>
<!--se incluye la vista search, que es una barra de busqueda-->
@include('ventas.venta.search')
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed table-hover">
<thead>
<th>
Fecha
</th>
<th>
Cliente
</th>
<th>
Comprobante
</th>
<th>
Impuesto
</th>
<th>
Total
</th>
<th>
Articulo
</th>
<th>Estado</th>
<th>Opciones</th>
</thead>
<!--Bucle que recorre todas los ingresos-->
@foreach ($ventas as $vent)
<tr>
<td>
{{ $vent->fecha_hora}}
</td>
<td>
{{ $vent->nombre}}
</td>
<td>
{{ $vent->tipo_comprobante.": ".$vent->serie_comprobante."-".$vent->num_comprobante}}
</td>
<td>
{{ $vent->impuesto}}
</td>
<td>
{{$vent->total_venta}}
</td>
<td>
{{$vent->nombre}}
</td>
<td>
{{$vent->estado}}
</td>
<td>
<a href="{{URL::action('VentaController@show',$vent->idventa)}}">
<button class="btn btn-primary">
Detalles
</button>
</a>
<a data-target="#modal-delete-{{$vent->idventa}}" data-toggle="modal" href="">
<button class="btn btn-danger">
Anular
</button>
</a>
</td>
</tr>
<!--modal de eliminar-->
@include('ventas.venta.eliminar')
@endforeach
</table>
</div>
<!--mostrar paginacion con el metodo render-->
{{$ventas->render()}}
</div>
</div>
@endsection