Title of the article might sound unclear, but let’s imagine you have customer list from Customer::all(), but then you need two separate lists/tables – customers from UK and from US. How to avoid two queries here? There’s a filter() function.
While working on migration files in Laravel, it’s relatively easy to forget one small detail which will restrict you from creating foreign keys. Let me tell you more.
Recently I’ve found out a nice little way to speed up generating of database stuff – I used to use make:migration and make:model Artisan commands separately. Apparently, they can be combined into one.
So you want to create your own package? Surprisingly, this topic has little information online and not properly described in the official docs. Let’s fill in the gaps and create a new Laravel 5 package from scratch.
If your application gets bigger, it makes sense to structure Controllers with sub-folders. But it takes a little more effort than just moving the files here and there. Let me explain the structure.
If you install a fresh Laravel and create your app, you may notice that all created_at and other timestamp fields in database are being saved in UTC timezone. How to change it? Easy.
Quick tip for today – let’s imagine we have a one-to-many relationship between Categories and Products, and we often show list of products here and there in our app. What if we want them ordered by name alphabetically? Should we add orderBy in every query? No, we can define that in relationship itself.
Today I want to talk about a feature of Laravel which is really useful but can be potentially difficult to understand at first. Pivot table is an example of intermediate table with relationships between two other “main” tables.
Quite often in bigger projects there are DB relationships with more than one level: categories->companies->products, countries->teams->players and similar. If we need to get the list of a deeper level, there’s a quick way of doing that with Eloquent.