gpt4 book ai didi

laravel - 如何在 Laravel 的 hasManyThrough 关系中删除 laravel_through_key

转载 作者:行者123 更新时间:2023-12-04 14:33:56 28 4
gpt4 key购买 nike

我有一个 hasManythrough 关系。如下:

public function contacts(){
return $this->hasManyThrough(ContactContent::class, Content::class,"id",'as_parent_content_id','as_parent_content_id','id');
}
public function getSupportElementsAttribute(){
return [
"contacts" => $this->contacts,
"documents" => $this->documents,
"assignments" => $this->assignments
];
}
这个返回是这样的:
"contacts": [
{
"id": 66,
"as_parent_content_id": 5074,
"created_at": "2020-09-30 16:21:11",
"updated_at": "2020-09-30 16:21:11",
"create_user_id": 1,
"laravel_through_key": 5074
}
],
如何删除这个 laravel_through_key ?

最佳答案

您可能想从集合中隐藏此列吗?然后 :

$user = User::with('posts')->get();
$user->makeHidden('laravel_through_key');
现在 laravel_through_key将从您的收藏中隐藏。
替代解决方案 : 添加 laravel_through_key在您模型的 $hidden属性,如:
protected $hidden = [
'laravel_through_key'
];

关于laravel - 如何在 Laravel 的 hasManyThrough 关系中删除 laravel_through_key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64150474/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com