Our blog

Filtering query results with different conditions on the same page

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.

Thursday, October 22nd, 2015

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.

Wednesday, October 21st, 2015

How to create migration file with Make:model command

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.

Tuesday, October 20th, 2015

How to create a Laravel 5 package in 10 easy steps

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.

Monday, October 19th, 2015

Moving Controllers to sub-folders in a correct way

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.

Monday, October 19th, 2015

Timezone settings for created_at and similar fields

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.

Thursday, October 15th, 2015

Eloquent Relationships – with “automatic” orderBy

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.

Wednesday, September 30th, 2015

Pivot tables and many-to-many relationships

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.

Tuesday, September 29th, 2015

Eloquent hasManyThrough: jumping deeper into relationships

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.

Monday, September 28th, 2015