| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use Livewire\WithPagination;
- class Anagrafica extends Component
- {
- use WithPagination;
- public $type;
- public $firstname;
- public $lastname;
- public $gender;
- public $birth_date;
- public $birth_town_id;
- public $birth_prov_id;
- public $residenza_town_id;
- public $residenza_prov_id;
- public $residenza_address;
- public $residenza_cap;
- public $mobile;
- public $sedicente;
- public $documento_tipo;
- public $documento_patente_cat;
- public $documento_tipo_altro;
- public $documento_numero;
- public $documento_rilasciato_da;
- public $documento_rilasciato_da_altro;
- public $foreign_country;
- public $documento_rilasciato_da_di_foreign_localita;
- public $documento_rilasciato_da_di_foreign_country;
- public $documento_rilasciato_da_prov_id;
- public $documento_rilasciato_da_town_id;
- public $documento_rilasciato_il;
- public $documento_scadenza_il;
- public $state;
- public $created;
- public $created_by;
- public $updated;
- public $updated_by;
- public $locked;
- public $locked_by;
- public $nazionalita;
- public $nazione_straniera;
- public $localita_straniera;
- public $rag_soc;
- public $vat;
- public $sede_legale_address;
- public $sede_legale_town_id;
- public $sede_legale_prov_id;
- public $sede_legale_cap;
- public $sede_legale_state;
- public $phone;
- public $recordId; // Used for editing/updating a record
- public $updateMode = false;
- public $anag_foreign_birth_country;
- public $anag_foreign_birth_city;
- public $anag_foreign_residence_country;
- public $anag_foreign_residence_city;
- protected $rules = [
- 'type' => '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->residenza_address = $record->anag_residenza_address;
- $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.');
- }
- }
|