MrPunyapal
MrPunyapal

Punyapal Shah ⚡

Verified

@MrPunyapal

Laravel Artisan | Open Source Contributor | Speaker | Core Team @Pinkary 🤌 Creator of @LaravelArtisans 🙌
2K Posts 20K Views
  • No matching results...
  • Searching...

/ 255

Laravel tip:

Don’t use `map()` when you are not transforming data.

If you only want to perform an action, use `each()`.

`map()` returns new values.

`each()` is for side effects.

Cleaner intent.
image

Laravel tip:

chunk() gives you records in batches.

lazy() lets you loop one record at a time without loading everything into memory.

Use chunk() when the batch matters.

Use lazy() when you want a clean loop.

Updating records while processing? Use chunkById() or lazyById().
image

Laravel tip:

Collection-style code is nice.

But if you call each() after get(), you already loaded everything into memory.

For large datasets, use lazy().
image

26

What is one coding thing you learned embarrassingly late?

The kind of thing that made you wonder how you missed it for so long.

32

Laravel security tip:

Your UI is not your security layer.

Hide the button if you want, but protect the backend action with a policy.
image