'required' ]; protected $messages = [ 'descrizione.required' => 'Il nome รจ obbligatorio' ]; public function resetFields(){ $this->descrizione = ''; $this->codicetoponimo = 0; $this->toponimo = ''; } public function updatingSearch() { $this->resetPage(); } public function render() { $rows = \App\Models\Stradario::where('descrizione', 'like', '%'.$this->search.'%')->orderBy('descrizione')->paginate(10); return view('livewire.stradario', ['records' => $rows]); } public function add() { $this->resetFields(); $this->add = true; $this->update = false; } public function store() { $this->validate(); try { \App\Models\Stradario::create([ 'descrizione' => $this->descrizione, 'codicetoponimo' => $this->codicetoponimo, 'toponimo' => $this->toponimo, ]); session()->flash('success','Record creato'); $this->resetFields(); $this->add = false; } catch (\Exception $ex) { session()->flash('error','Errore in fase di salvataggio'); } } public function edit($id){ try { $record = \App\Models\Stradario::findOrFail($id); if( !$record) { session()->flash('error','Record non trovato'); } else { $this->descrizione = $record->DESCRIZIONE; $this->codicetoponimo = $record->CODICETOPONIMO; $this->toponimo = $record->TOPONIMO; $this->dataId = $record->id; $this->update = true; $this->add = false; } } catch (\Exception $ex) { session()->flash('error','Errore'); } } public function update() { $this->validate(); try { \App\Models\Stradario::whereId($this->dataId)->update([ 'descrizione' => $this->descrizione, 'codicetoponimo' => $this->codicetoponimo, 'toponimo' => $this->toponimo, ]); session()->flash('success','Record aggiornato'); $this->resetFields(); $this->update = false; } catch (\Exception $ex) { session()->flash('success','Errore'); } } public function cancel() { $this->add = false; $this->update = false; $this->resetFields(); } public function delete($id) { try{ \App\Models\Stradario::find($id)->delete(); session()->flash('success',"Record eliminato"); }catch(\Exception $e){ session()->flash('error',"Errore"); } } }