'required', 'celular_comprarPromo' => 'required', 'email_comprarPromo' => 'required', 'cantidad_comprarPromo' => 'required', ]; public function render(Request $request) { if (empty($this->promo_id)) { $this->promo_id = $request->promo; } $consulta_promo = Promociones::find($this->promo_id); $this->consulta= $consulta_promo; $promociones= Promociones::where('visible','true')->get(); $fechaActual = Carbon::now(); $this->fechaHoy = $fechaActual; //dd($consulta_promo); $this->fechaFinal = $fechaActual->addDay($consulta_promo->dias); return view('livewire.show-index-promo',[ 'promo' => $consulta_promo, 'promociones'=>$promociones ]); } public function comprar() { $this->validate(); $usuario_existe = User::firstWhere('email', $this->email_comprarPromo)->id ?? null; if (is_null($usuario_existe)) { $usuario = new User; $usuario->name = $this->nombre_comprarPromo; $usuario->email = $this->email_comprarPromo; $usuario->password = '123'; $usuario->celular = $this->celular_comprarPromo; $usuario->save(); $usuario_id = $usuario->id; } else { $usuario_id = $usuario_existe; } if (empty(Auth::user())) { $historial = new Historiale(); $historial->fecha_inicio = $this->fechaHoy; $historial->fecha_final = $this->fechaFinal; $historial->valor = $this->consulta->precio *$this->cantidad_comprarPromo; $historial->tipo_pago = 'manual'; $historial->estado = 'pendiente'; $historial->vendedor_id = Role::where('nombre','super')->first()->usuarios->first()->id; $historial->promocion_id = $this->consulta->id; $historial->cliente_id = $usuario_id; $historial->cantidad = $this->cantidad_comprarPromo; $historial->save(); }else{ $historial = new Historiale; $historial->fecha_inicio = $this->fechaHoy; $historial->fecha_final = $this->fechaFinal; $historial->valor = $this->consulta->precio *$this->cantidad_comprarPromo ; $historial->tipo_pago = 'manual'; $historial->estado = 'pendiente'; $historial->vendedor_id = Auth::user()->id; $historial->promocion_id = $this->consulta->id; $historial->cliente_id = $usuario_id; $historial->cantidad = $this->cantidad_comprarPromo; $historial->save(); } return redirect('/comprar?monto='.$historial->valor.'&id='.$historial->id); } }