Tinker
What an answer is made of
Objects
Read a field with
->: $post->title, never ['title']. The id is ->id.Collections
Every list, at the top or inside an item:
count(), pluck(), where(), map().Dates
Carbon:
->updatedAt->toDateString(), ->diffForHumans().Choices
PHP enums. Their text is
->value.The moves you’ll use most
First, put the list in a variable.collect() fetches it once and keeps it, so each line below
reuses it instead of fetching every page again:
Chain them as you like:
$all->where('archived', false)->pluck('id').
Just the fields you want
map() turns each item into a small array, so you see only what matters:
Lists inside an item
They are Collections too, andpluck() reaches into nested fields with a dot:
As a plain array or JSON
toArray() and the JSON keep the API’s own names, so the id is _id there, while the object’s is ->id.One page, or all of them
- …All()
- …Pick()
- One page
listBlogsAll() returns every item, fetching page after page for you. Start here.In Tinker
An…All() list prints its items: Tinker fetches every page to show them. On a big list, add
->take(20) to see the first 20 only.
Next: errors
Nothing to catch, and what Laravel does with each failure.