Marian Pop ⚑ Laravel Magazine Profile picture
πŸ§™πŸ»β€β™‚οΈ Full-stack (Laravel, Vue, React) πŸ₯·πŸ» Creator of https://t.co/28Hx4ltzAl πŸ›°οΈ Sharing Laravel insights & πŸŽ™ Podcast at @LaravelMagazine πŸ‘€ Pronouns: vi/vim

Jan 22, 2022, 9 tweets

πŸ”₯ #Laravel Eloquent Models - [ πŸ₯·πŸ» "hidden" properties ]
We are all familiar with $table, $fillable, $dates and $appends and a few more but did you know there are more undocumented properties that we can make use of in our Laravel models?

Here is the complete list 🧡 πŸ‘‡πŸ»

1️⃣ You can specify the relations to eager load on every query for that model using $with

2️⃣ You can set how the relationship counts that should be eager loaded on every query for a given model

3️⃣ You can enable or disable lazy loading for a model using $preventsLazyLoading

4️⃣ You can limit the number of models to return for pagination using $perPage

5️⃣ You can indicate if the model was inserted during the current request lifecycle using $wasRecentlyCreated

6️⃣ If you want the object's string representation to be escaped when __toString is invoked you can set $escapeWhenCastingToString to true

7️⃣ You can indicate if broadcasting is currently enabled for a model using $isBroadcasting

8️⃣
BONUS - For all of the available options you can check out Laravel's model class:

github.com/laravel/framew…

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling