Класс ResourceContentModel будет расширять класс eloquent Model, а мои отдельные модели затем будут расширять ResourceContentModel.
Мой вопрос касается таких полей модели, как $with, $appends и $touches. . Если я использую их для каких-либо общих функций в ResourceContentModel, то, когда я переопределяю их в своем дочернем классе модели, они перезаписывают значения, которые я установил в своем родительском классе.
Ищете советы, как решить эту проблему?
Например:
Код: Выделить всё
class ResourceContentModel extends Model
{
protected $with = ['resource']
protected $appends = ['visibility']
public function resource()
{
return $this->morphOne(Resource::class, 'content');
}
public function getVisibilityAttribute()
{
return $this->resource->getPermissionScope(Permission::RESOURCE_VIEW);
}
}
class Photo extends ResourceContentModel
{
protected $with = ['someRelationship']
protected $appends = ['some_other_property']
THESE ARE A PROBLEM AS I LOSE THE VALUES IN ResourceContentModel
}
Подробнее здесь: https://stackoverflow.com/questions/446 ... odel-class