46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Livewire\Forms\ClientForm;
|
|
use App\Models\Client;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
use Exception;
|
|
|
|
class EditClient extends Component
|
|
{
|
|
|
|
public Client $client;
|
|
public ClientForm $clientForm;
|
|
|
|
#[On('update-client')]
|
|
public function loadClient($id)
|
|
{
|
|
try {
|
|
$this->client = Client::find($id);
|
|
|
|
if ($this->client) {
|
|
$this->clientForm->addClient($this->client);
|
|
}
|
|
} catch (Exception $e) {
|
|
$this->dispatch('notify', message: 'Ocorreu um erro inesperado ao editar o cliente. ' + $e);
|
|
}
|
|
}
|
|
public function edit($clientId)
|
|
{
|
|
$this->clientForm->validate();
|
|
|
|
try {
|
|
$this->clientForm->updateClient($this->client);
|
|
$this->dispatch('notify', message: $this->client->client_name + ' atualizado com sucesso!');
|
|
} catch (Exception $e) {
|
|
$this->dispatch('notify', message: 'Ocorreu um erro inesperado ao tentar confirmar edição do cliente. ' + $e);
|
|
}
|
|
}
|
|
public function render()
|
|
{
|
|
return view('livewire.admin.edit-client');
|
|
}
|
|
}
|