'required', 'estado_servicio' => 'required', 'pantallas' => 'required', 'completa' => 'required', ]; public function render() { if ($this->tiempo) { $this->pantallas = 1; $this->completa = 1; } $consulta = Servicio::Orderby('estado')->get(); return view('livewire.show-servicio', [ 'servicios' => $consulta, ]); } public function createServicio() { $this->validate(); if (!empty($this->photo)) { $nombre = Str::random(10); $img = img::make($this->photo)->orientate()->resize(1000, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode('webp'); $location = "photos/" . $nombre . ".webp"; Storage::disk('local')->put($location, $img); $url_foto = $location; } else { $url_foto = $this->img; } if (!empty($this->photo_inicio)) { $nombre_inicio = Str::random(10); $img_inicio = img::make($this->photo_inicio)->orientate()->resize(1000, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode('webp'); $location_inicio = "photos/" . $nombre_inicio . ".webp"; Storage::disk('local')->put($location_inicio, $img_inicio); $url_foto_inicio = $location_inicio; } else { $url_foto_inicio = null; } $servicio = new Servicio; $servicio->nombre = $this->nombre_servicio; $servicio->descripcion = $this->descripcion_servicio; $servicio->estado = $this->estado_servicio; $servicio->color_fondo = $this->color_servicio; $servicio->pantallas = $this->pantallas; $servicio->img = $url_foto; $servicio->img_inicio = $url_foto_inicio; $servicio->mensaje = $this->mensaje_servicio; $servicio->completa = $this->completa; $servicio->por_tiempo = $this->tiempo; $servicio->ver_perfiles = $this->perfiles; $servicio->perfiles = $this->password; $servicio->ver_url = $this->ver_url; $servicio->url = $this->url; $servicio->renovacion = $this->renovacion; $servicio->precio = $this->precio; $servicio->save(); $this->alert('success', 'Servicio creado correctamente!', [ 'position' => 'top' ]); $this->serviciosModal = false; } public function editar($id) { $consulta_servicios = Servicio::FindOrFail($id); $this->servicio_id = $consulta_servicios->id; $this->nombre_servicio = $consulta_servicios->nombre; $this->descripcion_servicio = $consulta_servicios->descripcion; $this->estado_servicio = $consulta_servicios->estado; $this->color_servicio = $consulta_servicios->color_fondo; $this->pantallas = $consulta_servicios->pantallas; $this->img = $consulta_servicios->img; $this->img_inicio = $consulta_servicios->img_inicio; $this->mensaje_servicio = $consulta_servicios->mensaje; $this->completa = $consulta_servicios->completa; $this->tiempo = $consulta_servicios->por_tiempo == 1 ? true : false; $this->perfiles = $consulta_servicios->ver_perfiles; $this->ver_url = $consulta_servicios->ver_url; $this->url = $consulta_servicios->url; $this->renovacion = $consulta_servicios->renovacion == 1 ? true : false; $this->precio = $consulta_servicios->precio; } public function guardar() { if (!empty($this->photo)) { $nombre = Str::random(10); $img = img::make($this->photo)->orientate()->resize(1000, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode('webp'); $location = "photos/" . $nombre . ".webp"; Storage::disk('local')->put($location, $img); $url_foto = $location; } else { $url_foto = $this->img; } if (!empty($this->photo_inicio)) { $nombre_inicio = Str::random(10); $img_inicio = img::make($this->photo_inicio)->orientate()->resize(1000, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->encode('webp'); $location_inicio = "photos/" . $nombre_inicio . ".webp"; Storage::disk('local')->put($location_inicio, $img_inicio); $url_foto_inicio = $location_inicio; } else { $url_foto_inicio = $this->img_inicio; } Servicio::where('id', $this->servicio_id)->update([ 'nombre' => $this->nombre_servicio, 'descripcion' => $this->descripcion_servicio, 'estado' => $this->estado_servicio, 'color_fondo' => $this->color_servicio, 'pantallas' => $this->pantallas, 'img' => $url_foto, 'img_inicio' => $url_foto_inicio, 'mensaje' => $this->mensaje_servicio, 'completa' => $this->completa, 'por_tiempo' => $this->tiempo == 1 ? true : false, 'ver_perfiles' => $this->perfiles, 'perfiles' => $this->password, 'ver_url' => $this->ver_url, 'url' => $this->url, 'renovacion' => $this->renovacion == 1 ? true : false, 'precio'=> $this->precio ]); $this->serviciosEditar = false; $this->limpiarInputServiciosModal(); } public function desactivar($id) { Servicio::where('id', $id)->update([ 'estado' => 'inactivo', ]); } public function activar($id) { Servicio::where('id', $id)->update([ 'estado' => 'activo', ]); } public function eliminar($id) { $this->delete_servicio = $id; $this->alert('warning', '¿Eliminar servicio?', [ 'position' => 'center', 'timer' => '10000', 'toast' => false, 'text' => 'Esta seguro', 'showConfirmButton' => true, 'onConfirmed' => 'confirmed', 'showDenyButton' => false, 'onDenied' => '', 'showCancelButton' => true, 'onDismissed' => '', 'cancelButtonText' => 'Salir', 'confirmButtonText' => 'Si', 'customClass' => [ 'confirmButton' => 'bg-green-500', 'denyButton' => 'bg-red-500', 'cancelButton' => 'bg-gray-500', ] ]); } public function getListeners() { return [ 'confirmed' ]; } public function confirmed() { Servicio::where('id', $this->delete_servicio)->delete(); } public function limpiarInputServiciosModal() { $this->nombre_servicio = ''; $this->descripcion_servicio = ''; $this->estado_servicio = null; $this->color_servicio = null; $this->pantallas = null; $this->photo = null; $this->photo_inicio = null; $this->mensaje_servicio = null; $this->completa = null; $this->tiempo = null; $this->renovacion = null; $this->servicio = null; } }