Back to Course |
Laravel 11 Eloquent: Expert Level

Model API Docs and 3 More Random Methods

The final thing I want to do in this section about various methods and properties of Eloquent Model structure is to refer you to the official API. Only a few people know that, but in addition to the official Laravel documentation, API documentation lists all potential methods, properties, and syntax options.

So if you go to laravel.com/api and look for an example, specifically for Model which is inside of Illuminate/Database/Eloquent, there's a considerable amount. You can find a lot of hidden gems.

For example, what I haven't shown you in this course, increment. There are a few methods to increment or decrement some values in your Eloquent Model instead of doing plus one and save or update you just increment or decrement by some amount.

Also, there's an interesting method called is. Instead of comparing two models and comparing their IDs manually, you can call on the Model is() method and pass another Model into the method. Eloquent would compare those objects and their IDs and return true or false.

Another example of interesting method called saveQuietly or updateQuietly. Using these methods when saving or updating events won't be fired. If you have observers, listeners on events, or something like that, they would not be fired if you save or update quietly.

These are just a few examples of interesting methods or methods that are fired under the hood when we call other methods. So for those, I recommend you plan some time because it's a very long page, or you can do that in batches daily. Analyze this page, and you will find something interesting you have yet to use.