
In the case of findOrFail() and firstOrFail(), Laravel throws an **Illuminate\Database\Eloquent\ModelNotFoundException** when it does not find a model. Let Laravel catch and handle the exception automatically. In this situation, when we're talking about not finding Eloquent records from the database, you have two options: Else it falls to the ground and the game ('app') grinds to a halt. Sounds logical, right? If someone throws a ball, someone needs to catch it. If an exception is thrown, then you need to catch it. That sounds scary – I mean, why would you want to manually throw exceptions, if you're only working to fix them? But it isn't scary at all. In this case, when Eloquent did not find an object, it throws an exception.

In this article I'll use the default Eloquent User model. So let's just get started and show a few examples. This gives you extreme versatility and allows you to perform almost any database operation. For example: $user = User::first() or $ralph = new User. For example: $users = User::all() gets all users. Interact with the database table as a whole. An Eloquent model is just a PHP class, that allows you to do two things: So, what is Eloquent exactly? Or what is an Eloquent model? It effectively comes down to the following: for each table you have in your database, you create an Eloquent model. In this tutorial I'll show you the basics of using Laravel Eloquent, so that you can start using Eloquent quickly. The Laravel Eloquent ORM is a way to interact with your database. Laravel Eloquent is one of Laravel's flagship features and one of the most notable things that distinguishes Laravel from other PHP frameworks.
