-
-
Save cursosdesarrolloweb/51871a87b74a2fc0794a299160302ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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