В моем случае я хочу различать, могу ли я загрузить желаемое значение из базы данных или если Мне нужно вернуть пользовательский объект, созданный в коде.
Это код функции getComponentACltAttribute моего класса Verification:
Код: Выделить всё
public function getComponentACltAttribute($value) {
if($this->superstructure_type == \Config::get('constants.superstructureTypes.standard')) {
return \App\Models\Werte\Product\Brettsperrholz::find($value);
}
else if($this->superstructure_type == \Config::get('constants.superstructureTypes.custom')) {
$customCltA = \App\Models\Werte\Product\BrettsperrholzBenutzerdefiniert::where('schichten_s',$this->component_a_number_of_layers)->where('decklagen_fk', $this->component_a_cover_layer->id)->first();
if($customCltA != null) {
$componentACustomClt = \App\Models\Werte\Product\Brettsperrholz::newModelInstance();
$componentACustomClt->id = 0;
$componentACustomClt->bezeichnung = '';
$componentACustomClt->hersteller_fk = 0;
$componentACustomClt->dicke_d = $this->component_a_thickness;
$componentACustomClt->schichten_s = $this->component_a_number_of_layers;
$componentACustomClt->decklagen_fk = $this->component_a_cover_layer;
$componentACustomClt->t_1 = $this->component_a_t_1;
...
$componentACustomClt->t_11 = $this->component_a_t_11;
$componentACustomClt->o_1 = $customCltA->o_1;
...
$componentACustomClt->o_11 = $customCltA->o_11;
$componentACustomClt->material = 'C24';
$componentACustomClt->zulassung_fk = 0;
return $componentACustomClt;
}
}
}
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/79245651/laravel-get-attribute-function-with-custom-created-return-or-database-loaded[/url]