Initialize concept of cached values

This commit is contained in:
Marcus Moore 2024-08-14 11:01:51 -07:00
parent 038e86954b
commit ab63a19aff
No known key found for this signature in database

View file

@ -2,6 +2,7 @@
namespace App\Livewire; namespace App\Livewire;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed; use Livewire\Attributes\Computed;
use Livewire\Component; use Livewire\Component;
@ -15,11 +16,19 @@ class CustomFieldSetDefaultValuesForModel extends Component
public $fieldset_id; public $fieldset_id;
public $model_id; public $model_id;
public Collection $cachedValues;
public function mount($model_id = null) public function mount($model_id = null)
{ {
$this->model_id = $model_id; $this->model_id = $model_id;
$this->fieldset_id = $this->model?->fieldset_id; $this->fieldset_id = $this->model?->fieldset_id;
$this->add_default_values = ($this->model?->defaultValues->count() > 0); $this->add_default_values = ($this->model?->defaultValues->count() > 0);
$this->cachedValues = collect();
$this->fields->each(function ($field) {
$this->cachedValues->put($field->db_column, $field->defaultValue($this->model_id));
});
} }
#[Computed] #[Computed]
@ -31,7 +40,13 @@ class CustomFieldSetDefaultValuesForModel extends Component
#[Computed] #[Computed]
public function fields() public function fields()
{ {
return CustomFieldset::find($this->fieldset_id)?->fields; $customFieldset = CustomFieldset::find($this->fieldset_id);
if ($customFieldset) {
return $customFieldset?->fields;
}
return collect();
} }
public function render() public function render()