'deleteMember' ]; protected $rules = [ 'first_name' => 'required', 'last_name' => 'required', ]; public function resetFields(){ $this->first_name = ''; $this->last_name = ''; $this->status = ''; $this->birth_city_id = null; $this->birth_province_id = null; $this->birth_nation_id = null; $this->birth_date = null; $this->gender = ''; $this->fiscal_code = ''; $this->address = ''; $this->zip_code = ''; $this->nation_id = null; $this->province_id = null; $this->city_id = null; $this->phone = ''; $this->email = ''; $this->enabled = true; } public function render() { $this->members = Member::select('id', 'first_name', 'last_name', 'status', 'enabled')->get(); return view('livewire.member'); } public function addMember() { $this->resetFields(); $this->addMember = true; $this->updateMember = false; } public function storeMember() { $this->validate(); try { Member::create([ 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'status' => $this->status, 'birth_city_id' => $this->birth_city_id, 'birth_province_id' => $this->birth_province_id, 'birth_nation_id' => $this->birth_nation_id, 'birth_date' => $this->birth_date, 'gender' => $this->gender, 'fiscal_code' => $this->fiscal_code, 'address' => $this->address, 'zip_code' => $this->zip_code, 'nation_id' => $this->nation_id, 'province_id' => $this->province_id, 'city_id' => $this->city_id, 'phone' => $this->phone, 'email' => $this->email, 'enabled' => $this->enabled ]); session()->flash('success, $Tesserato creato'); $this->resetFields(); $this->addMember = false; } catch (\Exception $ex) { session()->flash('error','Errore in fase di salvataggio'); } } public function editMember($id){ try { $member = Member::findOrFail($id); if( !$member) { session()->flash('error','Tesserato non trovato'); } else { $this->first_name = $member->first_name; $this->last_name = $member->last_name; $this->status = $member->status; $this->birth_city_id = $member->birth_city_id; $this->birth_province_id = $member->birth_province_id; $this->birth_nation_id = $member->birth_nation_id; $this->birth_date = $member->birth_date; $this->gender = $member->gender; $this->fiscal_code = $member->fiscal_code; $this->address = $member->address; $this->zip_code = $member->zip_code; $this->nation_id = $member->nation_id; $this->province_id = $member->province_id; $this->city_id = $member->city_id; $this->phone = $member->phone; $this->email = $member->email; $this->enabled = $member->enabled; $this->memberId = $member->id; $this->updateMember = true; $this->addMember = false; } } catch (\Exception $ex) { session()->flash('error','Errore'); } } public function updateMember() { $this->validate(); try { Member::whereId($this->memberId)->update([ 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'status' => $this->status, 'birth_city_id' => $this->birth_city_id, 'birth_province_id' => $this->birth_province_id, 'birth_nation_id' => $this->birth_nation_id, 'birth_date' => $this->birth_date, 'gender' => $this->gender, 'fiscal_code' => $this->fiscal_code, 'address' => $this->address, 'zip_code' => $this->zip_code, 'nation_id' => $this->nation_id, 'province_id' => $this->province_id, 'city_id' => $this->city_id, 'phone' => $this->phone, 'email' => $this->email, 'enabled' => $this->enabled ]); session()->flash('success','Tesserato aggiornato'); $this->resetFields(); $this->updateMember = false; } catch (\Exception $ex) { session()->flash('success','Errore'); } } public function cancelMember() { $this->addMember = false; $this->updateMember = false; $this->resetFields(); } public function deleteMember($id) { try{ Member::find($id)->delete(); session()->flash('success',"Tesserato eliminato"); }catch(\Exception $e){ session()->flash('error',"Errore"); } } }