laravel模型转数组时候如何去掉relations(关联模型)作为字数组?
我有两个模型,User和Commont模型,已定义好相关的关系。
User定义了一个方法,代码如下
public function testA()
{
$aaa= $this->commont->getPrice();//调用关联模型的方法 随便赋个值
dd($this->toArray());
}
然后控制器调用
$User = User('where',1231)->first();
$User->testA();
转换的数组里面,总有一个comment作为键值的二级数组,
请问怎么去掉呢?用最优的办法
$user->unsetRelation(‘comment’); //移除评论关系
$user->unsetRelations();//移除用户已加载的所有关系