What is the difference between find(), findOrFail(), first(), firstOrFail(), get(), list(), toArray()
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Diving Deep into Eloquent Methods - Find(), FindOrFail(), First(), FirstOrFail(), Get(), List() and toArray(): A Comprehensive Guide for Developers
Introduction: In the world of Laravel, Eloquent is a fantastic object-relational mapping tool that simplifies interacting with your database. It comes with numerous methods to help you perform various actions on your data models, such as finding and retrieving records. In this blog post, we'll explore some commonly used Eloquent methods and clarify the differences between them.
find()findOrFail()first()firstOrFail()get()list()toArray()
find(): This method is used to find a single record by its primary key. It's particularly helpful when you only require one specific model instance and are sure that it exists in the database. If the result isn't found, an exception will be thrown (unless you catch or handle it).
2. findOrFail(): Similar to find(), this method also retrieves a single record by its primary key. The major difference is that if the record doesn't exist, an exception is thrown that extends from ModelNotFoundException. This ensures that your application can gracefully handle missing models without crashing.
3. first(): In contrast to find() and findOrFail(), this method retrieves the first record in a set of records. It's appropriate when you need any available record from a matching query, allowing you to work with that specific result further down the line. Keep in mind that it doesn't guarantee the presence or absence of a record; hence, it may fail silently if no such record exists.
4. firstOrFail(): Much like findOrFail(), this method finds and retrieves the first available record from a set of records. However, it will throw an exception (an extended ModelNotFoundException) when no records match the query. This is useful if you want to ensure that your application has at least one valid result for further manipulation.
5. get(): When using get(), all matching records are fetched and returned as a collection object. Collections in Laravel help you work with multiple objects efficiently, providing methods like map() and filter(). This is ideal when your function requires an array of results or when working with iterable data structures.
6. list(): Use this method to return an array representing the given model's attributes as a list. It converts all model objects into simple arrays, making it useful when you need to pass a non-object entity to a PHP function or third-party library that doesn't support models directly.
7. toArray(): The toArray() method transforms the current model instance into an array with its attributes and relationships. This is a particularly helpful method when your application requires data in a flat structure (like an API). It enables you to serialize the model for external usage or storage without losing any essential information.
In conclusion, understanding the differences between these commonly used Eloquent methods will help you make better decisions about which one to use in specific scenarios. Remember that choosing the wrong method can lead to unexpected behavior and even application crashes. Always pick the one that best suits your needs, and don't forget about the importance of error handling and testing your code for potential issues.
To learn more about Eloquent methods and other Laravel concepts, visit our comprehensive learning resources at https://laravelcompany.com/articles.