Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anderking's avatar

How can I convert a query where it brings a collection of objects to a find or findOrFail?

How can I convert a query where a collection of objects brings me and therefore if I want to access an attribute of that object I have to cycle through it, unlike a find that brings me a different structure and I can directly access an attribute without need of the cycle, If I know that my query will bring me just one row how can I convert the structure where to find to be able to access directly to its attributes?

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

Use first() rather than get() if you want a Model instance rather than a Collection.

Please or to participate in this conversation.