How can I insert a sale by obtaining an instance of both models: ('departments', 'people'), with relationships of eloquent.
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();
}