How can I insert a sale using Laravel Eloquent?

1

How can I insert a sale by obtaining an instance of both models: ('departments', 'people'), with relationships of eloquent.

    
asked by Gregori Piñeres 01.02.2018 в 21:24
source

1 answer

2

First you must send the data of departamentos and personas from the controller:

public function index(){
   $personas = Personas::all();
   $departamentos = Deparamentos::all();
   return view('ventas.index', [
       'personas' => $personas,
       'departamentos' => $departamentos
   ]);
}

Then you send the id's of people and departments from your view to the controller and you get them back to the controller but to the store method:

public fuction store(Request $request){
    $venta = new Venta($request->all()); // Asumiendo que desde la vista mandas los 'names' de los 'id's' así: departamentoId, personaId
    $venta->save();
    return back();
}
    
answered by 02.02.2018 в 16:03