Quick Tips

How to Create ZIP Archive with Files And Download it in Laravel

If you need your users to be able to download multiple files at once, it's better to create one archive and let them download it. Here's how to do it in Laravel.

Eloquent Trick: Group By Raw with Boolean Condition

I know the title sounds unclear, so let me start with an example. What would be your Eloquent query if you have birth_date field in DB an want to show how many of your users are adult 18+ years, and how many are still children? Let's take a look.

Laravel Validation: Specify Attribute Names for Error Messages

Laravel validation system is great, including auto-populating error messages. But what if you want to override the names of the :attribute parameter values? Here's a simple example.

Laravel Route Filtering with Regular Expressions

Quick tip of the day. With routing you can specify Route::get('projects/{project_id}', 'ProjectController@show'); but what if you want project_id to be strictly a number?

Route Fallback: If No Other Route is Matched

Laravel 5.5.5 introduced a new feature in routing, called Route::fallback(). Basically, if no route is matched, then fallback function is a way...
extending laravel blade

Create Your Own Blade Directive: Example of br2nl in Laravel

Recently I had a task of textarea fields to save data with <brĀ /> for new lines in database but not show them...

How to Quickly Create Laravel User with Tinker

A new 2-minute video showing probably the quickest way to create a new user in Laravel users table.

How to Re-Use The Same FormRequest Class for Both store() and update() Actions

In your CRUD classes, it's good practice to use FormRequest classes for validation. Usually people create one for store() method and one for update() - something like StoreUserRequest and UpdateUserRequest. But maybe it's possible to combine them into one?

Eloquent withCount(): Get Related Records Amount

Eloquent has one less-known function called withCount(): it helps to get the amount of related records inside of the main object. It also works with two layers deep, inside of hasManyThrough relations. Let's take a look.

Group Entries By Day: Collection groupBy() With CallBack Function

Quite often we need to list the table of data not just entry by entry, but grouped by date. Sports games by...