我有具有多种帖子类型的帖子模型。我需要按帖子类型控制帖子属性。例如我有 2 种帖子类型:
仅建模一次发布。
后模型方案:
id
title
description
parent_id
type
请求
song
帖子类型时,如何自动将属性 singer
添加到响应数组或请求 singer
帖子类型添加属性 songs
?
我厌倦了使用
__construct()
方法在模型内部但不起作用:
public function __construct() {
if($this->type == "song") {
//$this->with = array_push($this->with, "singer");
$this->appends = array_push($this->appends, 'singer');
}
}
public function __construct() {
parent::__construct()
if($this->type == "song") {
//$this->with = array_push($this->with, "singer");
$this->appends = array_push($this->appends, 'singer');
}
}