54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Proclamatori;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\Proclamatore;
|
|
|
|
class ProclamatoreEdit extends Component
|
|
{
|
|
public Proclamatore $proclamatore;
|
|
public string $nome = '';
|
|
public string $cognome = '';
|
|
public bool $attivo = true;
|
|
|
|
public function mount(Proclamatore $proclamatore)
|
|
{
|
|
$this->proclamatore = $proclamatore;
|
|
$this->nome = $proclamatore->nome;
|
|
$this->cognome = $proclamatore->cognome;
|
|
$this->attivo = $proclamatore->attivo;
|
|
}
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'nome' => 'required|string|max:100',
|
|
'cognome' => 'required|string|max:100',
|
|
'attivo' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$this->validate();
|
|
|
|
$this->proclamatore->update([
|
|
'nome' => $this->nome,
|
|
'cognome' => $this->cognome,
|
|
'attivo' => $this->attivo,
|
|
]);
|
|
|
|
session()->flash('success', "Proclamatore {$this->proclamatore->nome_completo} aggiornato.");
|
|
return $this->redirect(route('proclamatori.index'), navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.proclamatori.proclamatore-form', [
|
|
'titolo' => "Modifica {$this->proclamatore->nome_completo}",
|
|
'btnLabel' => 'Salva Modifiche',
|
|
]);
|
|
}
|
|
}
|