funcion/pedido-ollas #47

Merged
rho merged 92 commits from funcion/pedido-ollas into master 2025-07-15 11:27:30 -03:00
Showing only changes of commit d890d405bd - Show all commits

View file

@ -26,24 +26,25 @@ class SubpedidoController extends Controller
return SubpedidoResource::collection(Subpedido::filtrar($filtros)->get());
}
public function store(Request $request)
public function store(Request $request)
{
$validado = $this->validateSubpedido();
if (Subpedido::where("nombre", $validado["nombre"])
->where("grupo_de_compra_id", $validado["grupo_de_compra_id"])
if (Subpedido::where([
"nombre" => $validado["nombre"],
"tipo_pedido_id" => $validado["tipo_pedido_id"],
"grupo_de_compra_id" => $validado["grupo_de_compra_id"]])
->get()
->count()
) {
throw new HttpException(400, "Ya existe un subpedido con este nombre");
}
->count())
throw new HttpException(400, "Ya existe un pedido con este nombre");
$s = new Subpedido();
$s->nombre = $validado["nombre"];
$s->grupo_de_compra_id = $validado["grupo_de_compra_id"];
$s->tipo_pedido_id = $validado["tipo_id"];
$s->save();
return $this->show($s);
$pedido = new Subpedido();
$pedido->nombre = $validado["nombre"];
$pedido->grupo_de_compra_id = $validado["grupo_de_compra_id"];
$pedido->tipo_pedido_id = $validado["tipo_id"];
$pedido->save();
return $this->show($pedido);
}
protected function validateSubpedido(): array