'required' ]; protected $messages = [ 'name.required' => 'Il nome รจ obbligatorio' ]; public function resetFields(){ $this->name = ''; $this->enabled = true; } public function mount() { $this->banks = \App\Models\Bank::select('id', 'name')->get(); } public function render() { $this->records = \App\Models\PaymentMethod::with('bank')->get(); return view('livewire.payment_method'); } public function add() { $this->resetFields(); $this->add = true; $this->update = false; } public function store() { $this->validate(); try { \App\Models\PaymentMethod::create([ 'name' => $this->name, 'bank_id' => $this->bank_id, 'enabled' => $this->enabled ]); session()->flash('success','Metodo pagamento creato'); $this->resetFields(); $this->add = false; } catch (\Exception $ex) { session()->flash('error','Errore in fase di salvataggio'); } } public function edit($id){ try { $payment_method = \App\Models\PaymentMethod::findOrFail($id); if( !$payment_method) { session()->flash('error','Metodo pagamento non trovato'); } else { $this->name = $payment_method->name; $this->enabled = $payment_method->enabled; $this->bank_id = $payment_method->bank_id; $this->dataId = $payment_method->id; $this->update = true; $this->add = false; } } catch (\Exception $ex) { session()->flash('error','Errore'); } } public function update() { $this->validate(); try { \App\Models\PaymentMethod::whereId($this->dataId)->update([ 'name' => $this->name, 'bank_id' => $this->bank_id, 'enabled' => $this->enabled ]); session()->flash('success','Metodo pagamento 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\PaymentMethod::find($id)->delete(); session()->flash('success',"Metodo pagamento eliminato"); }catch(\Exception $e){ session()->flash('error',"Errore"); } } }