Foreign keys with migrations: don't forget UNSIGNED
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.
In-depth Laravel tutorials covering advanced topics, real-world examples, and best practices.
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.
One of less-known but useful Eloquent functions are scopes - basically, you can define conditions to be re-used in various other places in code. Here's an overview.
Today I want to tell about another "trick" - or how to create a Laravel project without Command line or Terminal, directly from PhpStorm.