Mutable Carbon Dates Errors: Use copy() or CarbonImmutable
This is a typical error I see developers making: using `$date->addDays(1)` and then another `$date->addYears(1)` in the same request and getting wrong results. Let me explain.
In-depth Laravel tutorials covering advanced topics, real-world examples, and best practices.
This is a typical error I see developers making: using `$date->addDays(1)` and then another `$date->addYears(1)` in the same request and getting wrong results. Let me explain.
If you use Route Model Binding in your API Controllers and the record is not found, it will automatically return the 404 status code with an error message like "No query results for model [App\\Models\\User] 1". How can you override it?
When counting the Model records grouped by their type in a relationship, it's tempting to load too many DB queries or too much data into the memory. There are a few ways to optimize it, let's take a look at an example.
If you have Observer events on updated/deleted rows, it's important to know that they are fired only when you update individual rows, and not when doing mass-update or mass-delete.
If you have a Middleware, where you should use it: in the Routes file or in the Controller? Here are the FOUR options.
Some time ago I posted a tweet that went viral: it was my vision of how typical Laravel SaaS could be created, by just using the packages and tools from the community. In this article, I decided to expand and actually show you how it can be done.
Imagine you want to load the Model with its related many models, but sort those related results by some column in that related DB table. How to do that?
Imagine you want to show some "global" data in the Blade: for example, the number of new users this week on the top navigation. Not sure what Controllers would the data come from? Then you can perform that action in the Service Provider, in three ways.
When importing data from CSV or another source, you may need to check every record whether it exists in the DB already, and then update that record, otherwise create a new one. There are multiple ways to perform it.
To add a record to the database, you may use one of two methods. What is the difference?