Преобразование коллекции моделей в массив моделей ⇐ Php
Преобразование коллекции моделей в массив моделей
I have two models, Post and Comment; many comments belong to a single post. I'm trying to access all comments associated with a post as an array.
I have the following, which gives a collection.
$comments_collection = $post->comments()->get()
How would I turn this $comments_collection into an array? Is there a more direct way of accessing this array through eloquent relationships?
I have two models, Post and Comment; many comments belong to a single post. I'm trying to access all comments associated with a post as an array.
I have the following, which gives a collection.
$comments_collection = $post->comments()->get()
How would I turn this $comments_collection into an array? Is there a more direct way of accessing this array through eloquent relationships?
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение