mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
Initialize concept of cached values
This commit is contained in:
parent
038e86954b
commit
ab63a19aff
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue