gpt4 book ai didi

php - 如何在返回数据时禁用或删除 updated_At 和 Created_at

转载 作者:行者123 更新时间:2023-12-03 18:28:02 27 4
gpt4 key购买 nike

我试图在将响应返回给 api 之前删除 created_at 和 updated_at 。我想从 中删除这些字段Place_Type 和地点
我怎样才能做到这一点? :
我试过: unset(placetypes) 但它没有用

这是我的代码:

    public function places()
{

$placeType = PlaceType::with('places')->where('id', 1)->get();

return response()->json(['placeType' => $placeType]);
}

请求结果:
 "placeType": [
{
"id": 1,
"name": "Moriah O'Conner",
"icon": "https://picsum.photos/200/300",
"status": 1,
"created_at": "2019-12-14 18:23:19",
"updated_at": "2019-12-14 18:23:19",
"places": [
{
"id": 1,
"name": "Linda Leffler",
"description": "Alice's shoulder, and it set to work, and very soon came to ME, and told me he was in the air. She did it so VERY remarkable in that; nor did Alice think it would feel very queer to ME.' 'You!' said.",
"icon": "https://picsum.photos/200/300",
"image_name": "https://picsum.photos/200/300",
"rating": 2,
"longitude": -53.389979,
"latitude": 19.633458,
"availability": 1,
"status": 1,
"place_type_id": 1,
"created_at": "2019-12-14 18:23:19",
"updated_at": "2019-12-14 18:23:19"
},
{
"id": 2,
"name": "Lauren Cartwright",
"description": "I should say \"With what porpoise?\"' 'Don't you mean by that?' said the King. 'I can't remember half of anger, and tried to look at it!' This speech caused a remarkable sensation among the leaves.",
"icon": "https://picsum.photos/200/300",
"image_name": "https://picsum.photos/200/300",
"rating": 1,
"longitude": -38.117034,
"latitude": -32.248637,
"availability": 1,
"status": 1,
"place_type_id": 1,
"created_at": "2019-12-14 18:23:19",
"updated_at": "2019-12-14 18:23:19"
}...,
}

最佳答案

将字段添加到 $hidden 大批:

// Model

protected $hidden = ['created_at', 'updated_at'];

关于php - 如何在返回数据时禁用或删除 updated_At 和 Created_at,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59341772/

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