I have a component to edit some properties of a model. I don’t want to make the whole model public, so i only set the needed fields public (because it contains some sensitive data). However, I get the model via the mount() method. In another method, I save the settings. The thing where I am stuck is that I cant figure out how to save the model via the mount method so that I can access it in the save method without storing the model in a public property.
Here is my component, it works if the $company property is public. However, how do I hide the $company from the javascript?
class General extends Component
{
public $company;
public $companyArray;
public function saveCompany()
{
$validated = $this->validate([
'companyArray.street' => 'required|string',
'companyArray.house_number' => 'required|string',
'companyArray.zip' => 'required|digits:5',
'companyArray.city' => 'required|string'
]);
$this->company->update($validated['companyArray']);
}
public function mount(Company $company)
{
$this->company = $company;
$this->companyArray = [
'street' => $this->company->street,
'house_number' => $this->company->house_number,
'zip' => $this->company->zip,
'city' => $this->company->city
];
}
public function render()
{
return view('livewire.company.edit.general');
}
}