'deleteCard' ]; protected $rules = [ 'name' => 'required' ]; public function resetFields(){ $this->name = ''; $this->next_day_expire = ''; $this->next_month_expire = ''; $this->enabled = true; } public function render() { $this->cards = Card::select('id', 'name', 'enabled')->get(); return view('livewire.card'); } public function addCard() { $this->resetFields(); $this->addCard = true; $this->updateCard = false; } public function storeCard() { $this->validate(); try { Card::create([ 'name' => $this->name, 'next_day_expire' => $this->$next_day_expire, 'next_month_expire' => $this->$next_month_expire, 'enabled' => $this->enabled ]); session()->flash('success','Tessera creata'); $this->resetFields(); $this->addCard = false; } catch (\Exception $ex) { session()->flash('error','Errore'); } } public function editCard($id){ try { $card = Card::findOrFail($id); if( !$card) { session()->flash('error','Tessera non trovata'); } else { $this->name = $card->name; $this->enabled = $card->enabled; $this->next_day_expire = $card->next_day_expire; $this->next_month_expire = $card->next_month_expire; $this->cardId = $card->id; $this->updateCard = true; $this->addCard = false; } } catch (\Exception $ex) { session()->flash('error','Errore'); } } public function updateCard() { $this->validate(); try { Card::whereId($this->cardId)->update([ 'name' => $this->name, 'next_day_expire' => $this->$next_day_expire, 'next_month_expire' => $this->$next_month_expire, 'enabled' => $this->enabled ]); session()->flash('success','Tessera aggiornata'); $this->resetFields(); $this->updateCard = false; } catch (\Exception $ex) { session()->flash('success','Errore'); } } public function cancelCard() { $this->addCard = false; $this->updateCard = false; $this->resetFields(); } public function deleteCard($id) { try{ Card::find($id)->delete(); session()->flash('success',"Tessera eliminata"); }catch(\Exception $e){ session()->flash('error',"Errore"); } } }