如何从收藏品中获取 key ?
$posts= Post::all();
示例(不起作用):
$key = $posts->where('id', $id)->getKey();
最佳答案
all()
将返回一个没有键的集合。如果您谈论的是 0、1、2 等整数键,请使用 search()
方法:
$key = $posts->search(function($i) use($id) {
return $i->id === $id;
});
关于php - 从收藏品中获取 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49094933/