2021-03-18 16:12:39 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
use App\Models\CustomFieldset;
|
|
|
|
use App\Models\AssetModel;
|
|
|
|
|
|
|
|
class CustomFieldSetDefaultValuesForModel extends Component
|
|
|
|
{
|
|
|
|
public $add_default_values;
|
|
|
|
|
|
|
|
public $fieldset_id;
|
|
|
|
public $fields;
|
|
|
|
public $model_id;
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2021-09-30 16:21:23 -07:00
|
|
|
$this->model = AssetModel::find($this->model_id); // It's possible to do some clever route-model binding here, but let's keep it simple, shall we?
|
|
|
|
$this->fieldset_id = $this->model->fieldset_id;
|
2021-11-15 21:09:35 -08:00
|
|
|
|
|
|
|
$this->fields = null;
|
|
|
|
|
|
|
|
if ($fieldset = CustomFieldset::find($this->fieldset_id)) {
|
|
|
|
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->add_default_values = ($this->model->defaultValues->count() > 0);
|
2021-09-30 16:21:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function updatedFieldsetId()
|
|
|
|
{
|
2021-11-15 21:09:35 -08:00
|
|
|
if (CustomFieldset::find($this->fieldset_id)) {
|
|
|
|
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
|
|
|
|
}
|
|
|
|
|
2021-09-30 16:21:23 -07:00
|
|
|
}
|
|
|
|
|
2021-03-18 16:12:39 -07:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.custom-field-set-default-values-for-model');
|
|
|
|
}
|
|
|
|
}
|