Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created July 17, 2021 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cursosdesarrolloweb/51871a87b74a2fc0794a299160302ca0 to your computer and use it in GitHub Desktop.
Save cursosdesarrolloweb/51871a87b74a2fc0794a299160302ca0 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire\Service;
use Livewire\Component;
use Livewire\Redirector;
use App\Models\Service;
class Form extends Component
{
public Service $service;
public $textButton;
public $updating;
public function rules(): array {
if (!$this->updating) {
return [
'service.name' => 'required|string|min:6',
'service.default_hourly_rate_per_service' => 'required|numeric',
'service.comments' => 'nullable|string',
];
}
return [
'service.name' => 'required|string|min:6',
'service.default_hourly_rate_per_service' => 'required|numeric',
'service.comments' => 'nullable|string',
];
}
public function render()
{
return view('livewire.service.form');
}
public function store(): Redirector
{
$this->validate();
$this->service->user_id = auth()->id();
$this->service->save();
session()->flash('notification', ['type' => 'success', 'title' => __("Servicio creado"), 'message' => __("El Servicio ha sido creado correctamente")]);
return redirect()->to(route("services.index"));
}
public function update(): Redirector
{
$this->validate();
$this->service->save();
session()->flash('notification', ['type' => 'success', 'title' => __("Servicio actualizado"), 'message' => __("El Servicio ha sido actualizado correctamente")]);
return redirect()->to(route("services.index"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment