'required|string|max:255', 'firstname' => 'required|string|max:255', 'lastname' => 'required|string|max:255', // Add other validation rules as needed ]; public function render() { return view('livewire.anagrafica-crud', [ 'anagraficas' => Anagrafica::paginate(10) ]); } public function resetInputFields() { $this->type = ''; $this->firstname = ''; $this->lastname = ''; $this->gender = ''; $this->birth_date = ''; $this->birth_town_id = ''; $this->birth_prov_id = ''; $this->residenza_town_id = ''; $this->residenza_prov_id = ''; $this->residenza_address = ''; $this->residenza_cap = ''; $this->mobile = ''; $this->sedicente = ''; $this->documento_tipo = ''; $this->documento_patente_cat = ''; $this->documento_tipo_altro = ''; $this->documento_numero = ''; $this->documento_rilasciato_da = ''; $this->documento_rilasciato_da_altro = ''; $this->foreign_country = ''; $this->documento_rilasciato_da_di_foreign_localita = ''; $this->documento_rilasciato_da_di_foreign_country = ''; $this->documento_rilasciato_da_prov_id = ''; $this->documento_rilasciato_da_town_id = ''; $this->documento_rilasciato_il = ''; $this->documento_scadenza_il = ''; $this->state = ''; $this->created = ''; $this->created_by = ''; $this->updated = ''; $this->updated_by = ''; $this->locked = ''; $this->locked_by = ''; $this->nazionalita = ''; $this->nazione_straniera = ''; $this->localita_straniera = ''; $this->rag_soc = ''; $this->vat = ''; $this->sede_legale_address = ''; $this->sede_legale_town_id = ''; $this->sede_legale_prov_id = ''; $this->sede_legale_cap = ''; $this->sede_legale_state = ''; $this->phone = ''; $this->anag_foreign_birth_country = ''; $this->anag_foreign_birth_city = ''; $this->anag_foreign_residence_country = ''; $this->anag_foreign_residence_city = ''; } public function store() { $this->validate(); Anagrafica::create([ 'type' => $this->type, 'firstname' => $this->firstname, 'lastname' => $this->lastname, 'gender' => $this->gender, 'birth_date' => $this->birth_date, 'birth_town_id' => $this->birth_town_id, 'birth_prov_id' => $this->birth_prov_id, 'residenza_town_id' => $this->residenza_town_id, 'residenza_prov_id' => $this->residenza_prov_id, 'residenza_address' => $this->residenza_address, 'residenza_cap' => $this->residenza_cap, 'mobile' => $this->mobile, 'sedicente' => $this->sedicente, 'documento_tipo' => $this->documento_tipo, 'documento_patente_cat' => $this->documento_patente_cat, 'documento_tipo_altro' => $this->documento_tipo_altro, 'documento_numero' => $this->documento_numero, 'documento_rilasciato_da' => $this->documento_rilasciato_da, 'documento_rilasciato_da_altro' => $this->documento_rilasciato_da_altro, 'foreign_country' => $this->foreign_country, 'documento_rilasciato_da_di_foreign_localita' => $this->documento_rilasciato_da_di_foreign_localita, 'documento_rilasciato_da_di_foreign_country' => $this->documento_rilasciato_da_di_foreign_country, 'documento_rilasciato_da_prov_id' => $this->documento_rilasciato_da_prov_id, 'documento_rilasciato_da_town_id' => $this->documento_rilasciato_da_town_id, 'documento_rilasciato_il' => $this->documento_rilasciato_il, 'documento_scadenza_il' => $this->documento_scadenza_il, 'state' => $this->state, 'created' => $this->created, 'created_by' => $this->created_by, 'updated' => $this->updated, 'updated_by' => $this->updated_by, 'locked' => $this->locked, 'locked_by' => $this->locked_by, 'nazionalita' => $this->nazionalita, 'nazione_straniera' => $this->nazione_straniera, 'localita_straniera' => $this->localita_straniera, 'rag_soc' => $this->rag_soc, 'vat' => $this->vat, 'sede_legale_address' => $this->sede_legale_address, 'sede_legale_town_id' => $this->sede_legale_town_id, 'sede_legale_prov_id' => $this->sede_legale_prov_id, 'sede_legale_cap' => $this->sede_legale_cap, 'sede_legale_state' => $this->sede_legale_state, 'phone' => $this->phone, 'anag_foreign_birth_country' => $this->anag_foreign_birth_country, 'anag_foreign_birth_city' => $this->anag_foreign_birth_city, 'anag_foreign_residence_country' => $this->anag_foreign_residence_country, 'anag_foreign_residence_city' => $this->anag_foreign_residence_city, ]); session()->flash('message', 'Record Created Successfully.'); $this->resetInputFields(); } public function edit($id) { $record = Anagrafica::findOrFail($id); $this->recordId = $id; $this->type = $record->type; $this->firstname = $record->firstname; $this->lastname = $record->lastname; $this->gender = $record->gender; $this->birth_date = $record->birth_date; $this->birth_town_id = $record->birth_town_id; $this->birth_prov_id = $record->birth_prov_id; $this->residenza_town_id = $record->residenza_town_id; $this->residenza_prov_id = $record->residenza_prov_id; $this->residenza_address = $record->residenza_address; $this->residenza_cap = $record->residenza_cap; $this->mobile = $record->mobile; $this->sedicente = $record->sedicente; $this->documento_tipo = $record->documento_tipo; $this->documento_patente_cat = $record->documento_patente_cat; $this->documento_tipo_altro = $record->documento_tipo_altro; $this->documento_numero = $record->documento_numero; $this->documento_rilasciato_da = $record->documento_rilasciato_da; $this->documento_rilasciato_da_altro = $record->documento_rilasciato_da_altro; $this->foreign_country = $record->foreign_country; $this->documento_rilasciato_da_di_foreign_localita = $record->documento_rilasciato_da_di_foreign_localita; $this->documento_rilasciato_da_di_foreign_country = $record->documento_rilasciato_da_di_foreign_country; $this->documento_rilasciato_da_prov_id = $record->documento_rilasciato_da_prov_id; $this->documento_rilasciato_da_town_id = $record->documento_rilasciato_da_town_id; $this->documento_rilasciato_il = $record->documento_rilasciato_il; $this->documento_scadenza_il = $record->documento_scadenza_il; $this->state = $record->state; $this->created = $record->created; $this->created_by = $record->created_by; $this->updated = $record->updated; $this->updated_by = $record->updated_by; $this->locked = $record->locked; $this->locked_by = $record->locked_by; $this->nazionalita = $record->nazionalita; $this->nazione_straniera = $record->nazione_straniera; $this->localita_straniera = $record->localita_straniera; $this->rag_soc = $record->rag_soc; $this->vat = $record->vat; $this->sede_legale_address = $record->sede_legale_address; $this->sede_legale_town_id = $record->sede_legale_town_id; $this->sede_legale_prov_id = $record->sede_legale_prov_id; $this->sede_legale_cap = $record->sede_legale_cap; $this->sede_legale_state = $record->sede_legale_state; $this->phone = $record->phone; $this->anag_foreign_birth_country = $record->anag_foreign_birth_country; $this->anag_foreign_birth_city = $record->anag_foreign_birth_city; $this->anag_foreign_residence_country = $record->anag_foreign_residence_country; $this->anag_foreign_residence_city = $record->anag_foreign_residence_city; $this->updateMode = true; } public function update() { $this->validate(); if ($this->recordId) { $record = Anagrafica::find($this->recordId); $record->update([ 'type' => $this->type, 'firstname' => $this->firstname, 'lastname' => $this->lastname, 'gender' => $this->gender, 'birth_date' => $this->birth_date, 'birth_town_id' => $this->birth_town_id, 'birth_prov_id' => $this->birth_prov_id, 'residenza_town_id' => $this->residenza_town_id, 'residenza_prov_id' => $this->residenza_prov_id, 'residenza_address' => $this->residenza_address, 'residenza_cap' => $this->residenza_cap, 'mobile' => $this->mobile, 'sedicente' => $this->sedicente, 'documento_tipo' => $this->documento_tipo, 'documento_patente_cat' => $this->documento_patente_cat, 'documento_tipo_altro' => $this->documento_tipo_altro, 'documento_numero' => $this->documento_numero, 'documento_rilasciato_da' => $this->documento_rilasciato_da, 'documento_rilasciato_da_altro' => $this->documento_rilasciato_da_altro, 'foreign_country' => $this->foreign_country, 'documento_rilasciato_da_di_foreign_localita' => $this->documento_rilasciato_da_di_foreign_localita, 'documento_rilasciato_da_di_foreign_country' => $this->documento_rilasciato_da_di_foreign_country, 'documento_rilasciato_da_prov_id' => $this->documento_rilasciato_da_prov_id, 'documento_rilasciato_da_town_id' => $this->documento_rilasciato_da_town_id, 'documento_rilasciato_il' => $this->documento_rilasciato_il, 'documento_scadenza_il' => $this->documento_scadenza_il, 'state' => $this->state, 'created' => $this->created, 'created_by' => $this->created_by, 'updated' => $this->updated, 'updated_by' => $this->updated_by, 'locked' => $this->locked, 'locked_by' => $this->locked_by, 'nazionalita' => $this->nazionalita, 'nazione_straniera' => $this->nazione_straniera, 'localita_straniera' => $this->localita_straniera, 'rag_soc' => $this->rag_soc, 'vat' => $this->vat, 'sede_legale_address' => $this->sede_legale_address, 'sede_legale_town_id' => $this->sede_legale_town_id, 'sede_legale_prov_id' => $this->sede_legale_prov_id, 'sede_legale_cap' => $this->sede_legale_cap, 'sede_legale_state' => $this->sede_legale_state, 'phone' => $this->phone, 'anag_foreign_birth_country' => $this->anag_foreign_birth_country, 'anag_foreign_birth_city' => $this->anag_foreign_birth_city, 'anag_foreign_residence_country' => $this->anag_foreign_residence_country, 'anag_foreign_residence_city' => $this->anag_foreign_residence_city, ]); $this->updateMode = false; session()->flash('message', 'Record Updated Successfully.'); $this->resetInputFields(); } } public function delete($id) { Anagrafica::find($id)->delete(); session()->flash('message', 'Record Deleted Successfully.'); } }