|
|
@@ -8,6 +8,8 @@ use Livewire\Attributes\Validate;
|
|
|
class Resource extends Component
|
|
|
{
|
|
|
|
|
|
+ public $resources;
|
|
|
+
|
|
|
#[Validate('required')]
|
|
|
public $first_name = '';
|
|
|
public $last_name = '';
|
|
|
@@ -27,57 +29,101 @@ class Resource extends Component
|
|
|
|
|
|
public $is_edit = false;
|
|
|
|
|
|
- public function render()
|
|
|
+ public function resetFields()
|
|
|
{
|
|
|
+ $this->first_name = '';
|
|
|
+ $this->last_name = '';
|
|
|
+ $this->birth_day = null;
|
|
|
+ $this->birth_place_id = null;
|
|
|
+ $this->fiscal_code = '';
|
|
|
+ $this->phone = '';
|
|
|
+ $this->email = '';
|
|
|
+ $this->address = '';
|
|
|
+ $this->zip = '';
|
|
|
+ $this->city_id = null;
|
|
|
+ $this->country_id = null;
|
|
|
+ $this->domicile = '';
|
|
|
+ $this->enabled = true;
|
|
|
+ }
|
|
|
|
|
|
+ public function render()
|
|
|
+ {
|
|
|
// Get Resource
|
|
|
- $this->current_resource = \App\Models\Resource::first();
|
|
|
-
|
|
|
- if ($this->current_resource != null)
|
|
|
- {
|
|
|
-
|
|
|
- $this->first_name = $this->current_resource->first_name;
|
|
|
- $this->last_name = $this->current_resource->last_name;
|
|
|
- $this->birth_day = $this->current_resource->birth_day;
|
|
|
- $this->birth_place_id = $this->current_resource->birth_place_id;
|
|
|
- $this->fiscal_code = $this->current_resource->fiscal_code;
|
|
|
- $this->phone = $this->current_resource->phone;
|
|
|
- $this->email = $this->current_resource->email;
|
|
|
- $this->address = $this->current_resource->address;
|
|
|
- $this->zip = $this->current_resource->zip;
|
|
|
- $this->city_id = $this->current_resource->city_id;
|
|
|
- $this->country_id = $this->current_resource->country_id;
|
|
|
- $this->domicile = $this->current_resource->domicile;
|
|
|
- $this->enabled = $this->current_resource->enabled;
|
|
|
+ $this->resources = \App\Models\Resource::all();
|
|
|
+ return view('livewire.resource');
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ public function add()
|
|
|
+ {
|
|
|
+ $this->resetFields();
|
|
|
+ $this->is_edit = true;
|
|
|
+ $this->current_resource = null;
|
|
|
+ }
|
|
|
|
|
|
- return view('livewire.resource');
|
|
|
+ public function edit($id)
|
|
|
+ {
|
|
|
+ $this->resetFields();
|
|
|
+ $this->is_edit = true;
|
|
|
+ $this->current_resource = \App\Models\Recource::findOrFail($id);
|
|
|
+ $this->first_name = $this->current_resource->first_name;
|
|
|
+ $this->last_name = $this->current_resource->last_name;
|
|
|
+ $this->birth_day = $this->current_resource->birth_day;
|
|
|
+ $this->birth_place_id = $this->current_resource->birth_place_id;
|
|
|
+ $this->fiscal_code = $this->current_resource->fiscal_code;
|
|
|
+ $this->phone = $this->current_resource->phone;
|
|
|
+ $this->email = $this->current_resource->email;
|
|
|
+ $this->address = $this->current_resource->address;
|
|
|
+ $this->zip = $this->current_resource->zip;
|
|
|
+ $this->city_id = $this->current_resource->city_id;
|
|
|
+ $this->country_id = $this->current_resource->country_id;
|
|
|
+ $this->domicile = $this->current_resource->domicile;
|
|
|
+ $this->enabled = $this->current_resource->enabled;
|
|
|
}
|
|
|
|
|
|
- public function update()
|
|
|
+ public function save()
|
|
|
{
|
|
|
|
|
|
$this->validate();
|
|
|
|
|
|
try {
|
|
|
- $this->current_resource->update([
|
|
|
- 'first_name' => $this->first_name,
|
|
|
- 'last_name' => $this->last_name,
|
|
|
- 'birth_day' => $this->birth_day,
|
|
|
- 'birth_place_id' => $this->birth_place_id,
|
|
|
- 'fiscal_code' => $this->fiscal_code,
|
|
|
- 'phone' => $this->phone,
|
|
|
- 'email' => $this->email,
|
|
|
- 'address' => $this->address,
|
|
|
- 'zip' => $this->zip,
|
|
|
- 'city_id' => $this->city_id,
|
|
|
- 'country_id' => $this->country_id,
|
|
|
- 'domicile' => $this->domicile,
|
|
|
- 'enabled' => $this->enabled,
|
|
|
- ]);
|
|
|
+ if ($this->current_customer == null)
|
|
|
+ {
|
|
|
+ \App\Models\Resource::create([
|
|
|
+ 'first_name' => $this->first_name,
|
|
|
+ 'last_name' => $this->last_name,
|
|
|
+ 'birth_day' => $this->birth_day,
|
|
|
+ 'birth_place_id' => $this->birth_place_id,
|
|
|
+ 'fiscal_code' => $this->fiscal_code,
|
|
|
+ 'phone' => $this->phone,
|
|
|
+ 'email' => $this->email,
|
|
|
+ 'address' => $this->address,
|
|
|
+ 'zip' => $this->zip,
|
|
|
+ 'city_id' => $this->city_id,
|
|
|
+ 'country_id' => $this->country_id,
|
|
|
+ 'domicile' => $this->domicile,
|
|
|
+ 'enabled' => $this->enabled
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $this->current_resource->update([
|
|
|
+ 'first_name' => $this->first_name,
|
|
|
+ 'last_name' => $this->last_name,
|
|
|
+ 'birth_day' => $this->birth_day,
|
|
|
+ 'birth_place_id' => $this->birth_place_id,
|
|
|
+ 'fiscal_code' => $this->fiscal_code,
|
|
|
+ 'phone' => $this->phone,
|
|
|
+ 'email' => $this->email,
|
|
|
+ 'address' => $this->address,
|
|
|
+ 'zip' => $this->zip,
|
|
|
+ 'city_id' => $this->city_id,
|
|
|
+ 'country_id' => $this->country_id,
|
|
|
+ 'domicile' => $this->domicile,
|
|
|
+ 'enabled' => $this->enabled,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
session()->flash('success','Dato aggiornato');
|
|
|
- //$this->resetFields();
|
|
|
+ $this->resetFields();
|
|
|
$this->is_edit = false;
|
|
|
} catch (\Exception $ex) {
|
|
|
session()->flash('error','Errore (' . $ex->getMessage() . ')');
|
|
|
@@ -85,4 +131,11 @@ class Resource extends Component
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public function cancel()
|
|
|
+ {
|
|
|
+ $this->resetFields();
|
|
|
+ $this->is_edit = false;
|
|
|
+ $this->current_company = null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|