The `Carbon` class for dates and times is a part of Laravel by default, but there's also a less-known class, `CarbonPeriod`. It can help generate the ARRAY of datetimes, often useful for report tables and calendars. In this tutorial, let's look at the 7 most practical examples of `CarbonPeriod`.
JSON columns in the database seem like a solution if you're not sure about the structure of data. But quite often, they lead to more problems in the future. In this article, I want to show both good and bad cases of using JSON columns with Laravel examples.
If you have a `hasMany` relationship and want to get the parent record with a total sum of specific children column values and order by it, here's how to do it.
When structuring a database, similar relationships may repeat, like a Task may be assigned to a User, User Group, or User Role. Is it worth thinking about polymorphic? In this example, let's compare the performance and convenience to use.
Laravel Breeze starter kit registers users and log them in automatically, redirecting to the dashboard. But what if you want the person to log in manually, putting their email and password again after registration?
When do you need to create interfaces in PHP/Laravel? Suppose you have a method with different implementations depending on some condition. In that case, it may be a candidate for an interface, with different classes implementing that interface method differently, depending on that condition. Let me show an example.
When writing automated tests, sometimes you want to repeat the same test multiple times on various data inputs. In Laravel, you can do this easily with data providers and datasets. I will show you a PHPUnit and a Pest example.
One of the typical issues with pagination is if you have more filters with GET parameters on your page. How to keep them from disappearing when the user clicks to visit "/?page=2"?
If you have a Laravel many-to-many relationship and need to sort the Collection by the pivot table value, the query may be complicated. Let's take a look at this example.