Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created Jul 17, 2021
Embed
What would you like to do?
<?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