我有以下数据:
[{
"id": 1,
"name": "test1",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 2,
"name": "test12",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 3,
"name": "test123",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 4,
"name": "test1234",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 5,
"name": "test12345",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 6,
"name": "test123456",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 7,
"name": "test1234567",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 8,
"name": "test12345678",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 9,
"name": "test123456789",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 10,
"name": "test1234567890",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 11,
"name": "test12345678901",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}, {
"id": 12,
"name": "test123456789012",
"created_at": "2020-01-30 15:55:44",
"updated_at": "2020-01-30 15:55:44"
}]
此数据是通过雄辩的模型检索的,如下所示:
$ad_groups = Ad_user::find($request->decodedToken->user_id)->ad_groups()->get();
我不知道雄辩模型的任何“继承”功能是否仍然存在于$ad_groups
中,这就是为什么我在这里为您发布它,以便您知道我们必须使用的^^
我基本上要完成的工作是使id超出。我当然可以编写一个foreach循环。但是我是Lumen / Laravel的新手,我想知道在这种情况下是否还有一些很棒的方法,例如...>getMeWhatIWant()
:D
您可以在Laravel集合(pluck
)上使用official docs here方法。
您只需将要检索的列名作为第一个参数传递:
$ids = $ad_groups->pluck('id');
dd($ids);