π₯ #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:
Laravel makes it simple to create background-processing queued jobs. Your application can reply to web requests with lightning speed and give your clients a better user experience by transferring time-consuming operations to a queue.
Laravel Queues [ Pocket Guide ] 𧡠ππ»
1οΈβ£ Dispatching and running jobs
You can create a new job running the following artisan command:
2οΈβ£ Queues to database
In order for the queues to use your database, you have to configure the queue connection in queue.php to point to your database. Once that is configured, you have to create two tables in your database: jobs and failed_jobs:
π₯ Epic Laravel Tips Thread π₯ [ Part 1 ] I decided to create weekly threads and share epic @laravelphp tips that will lead to a cleaner and more performant code!
π₯ Epic Laravel π₯ - Tip No. 1 [ Eloquent Global Query Scopes ] Implementing your own eloquent global query scopes can be a quick and straightforward approach to ensure that all queries for a given model are subject to certain limitations:
2/11
π₯ Epic Laravel π₯ - Tip No. 2 [ Conditional Relationships ]
Relationships allow for powerful method chaining and querying. However, for consistency reasons consider creating a separate relationship method that includes the desired chaining or querying:
3/11