Quick Tips

How to set auto-increment start in Laravel migrations?

Laravel has a great database migration mechanism, but there are some things missing there. For example, what if you want your IDs start with some number, like 140001, 140002 etc?

Differences: $request->get() vs $request->input() vs request() vs get_data()

How do you handle POST data in your store() or update() methods? Seems like a simple question, but actually there are so many options!

Laravel simplePaginate: more effective with bigger data

Laravel pagination is quite a simple thing to use, but to determine the amount of pages it makes additional query to the database, which may be a problem for bigger amount of data. And you can actually avoid it.

Laravel Blade foreach “trick”: splitting results into chunks

Imagine a situation that you have 10 records to show in Blade but you need to show them in 2 sections, five records each. There's a pretty nice trick how to do that in @foreach loop.

Laravel: Two Ways to Seed Data with Relationships

While seeding data, it's common to have one class for each database table. But what if there are relationships? I will show you two...

Eloquent::when(): No More if-elses for Conditional Queries

For a while many of us used to write conditional queries with "if-else". What if I told you there's a (much) better way? Easily readable and more Laravel-ish.

Change created_at and updated_at names to other fields

Let's imagine a scenario where you have an old database and re-writing codebase to Laravel. Database structure may not follow Laravel standards - created_at and updated_at fields are named differently. How can you "tell it to Laravel"?

Datatables stateSave option: “remember” search and filters

Not Laravel related, but today encountered the situation, so sharing with you. You probably know Datatables, right? It allows to quickly search and filter the table of data. But what if user then navigates away (for Edit, for example) and then wants to go back and have the same search parameters he had before? Easy.

BelongsTo Default Models: No Need to Check in Blade Files

I've recently found out about a feature in Laravel relationship which changed the way I write code. So sharing with you.

Resource Controllers for API: How to Remove create/edit methods?

Resource controllers are great for CRUDs, but if we use them for APIs, there are two unnecessary methods - create() and edit(), cause there are no visual forms for it. So how to remove them from routes? There are two ways.