Quick Tips

Get Array of IDs from Eloquent Collection: pluck() or modelKeys()

There are situations where you need to get array of IDs for some records in collection/table. I will show you two quick ways to do it - one is pretty popular, and another is a function which I found out only today.

Laravel: Get Newest/Oldest Records from Pivot Table in BelongsToMany

Default belongsToMany relationship in Laravel works really well - you can easily attach, detach or sync records. But what if you want to order pivot records by newest or oldest? This article will show you how.

“Posts Per Page”: How to Save Setting for Every User Individually

In typical project with list and pagination, you should have a choice to select, how many entries you want to see per page - 10, 25, 50, 100 etc. That setting probably refreshes the table or the whole page, but how to save it for the next time that user logs in, or visits the page in a week?

Resize Images in Laravel with Spatie Media Library

Really popular Laravel Media Library package has one less-known feature - image resizing. The best part is that it's really simple to add, let me show you how.

Laravel 5.8: Automatic Policy Resolution

One of the new features in Laravel 5.8 allows you to not register your policies in AuthServiceProvider, they will be "guessed" automatically. Here's how it works.

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...

STAY CONNECTED

2,006FansLike
8,361FollowersFollow
10,300SubscribersSubscribe

NEWEST VIDEOS

RANDOM ARTICLES