Laravel Pro Tips
#eloquent #models #DB
🌟 Eloquent tip If you need to insert or update a whole bunch of records in a loop, don't use `Model::updateOrCreate`. Instead, use the `DB` facade's `upsert` method to use your database's built-in upsert functionality to do the whole thing in one query!
Kai Sassnowski 🥔
#eloquent #models
🔥 #Laravel Tip: Knowing the difference between calling ‘fresh’ or ‘refresh’ on a model is quite important. If you’re new to the framework, then here’s a simple explanation on how they differ.
Matt Kingshott
#routes #models
Laravel tip 💡You can use the 'resolveRouteBinding' method on your model to modify the value that is used to resolve the binding.
Philo Hermans
#models #events
🔥 #Laravel Tip: At scale, calculating metrics for dashboards can take a long time, as you might have to count thousands or even millions of records. Fortunately, you can easily fix this by using model events to maintain stats. Here’s a simple example:
#eloquent #models #relationships
🌶️ #Laravel Tip: The Eloquent push() method allows you to save the Model and all of its relations in one shot. Compared to the save() that only saves the Model itself. Here's a practical example to illustrate 🔥 https://t.co/N6q2wyDrya #PHP #Laravel
Bilal Haidar - Available 4 Laravel gigs
#models #factories
🔥 Laravel Tip: Factory states You can create factory states in your model factories to hide the details about the model attributes and make your tests more readable.
Cosme Escobedo
#Laravel Tip 🔥 When using a custom keyed implicit binding as a nested route parameter, Laravel will automatically scope the query to retrieve the nested model by its parent using conventions to guess the relationship name on the parent.
Sanjit Singh
#Laravel Eloquent Tip 🔥 You can use 'save' and 'saveMany' methods for adding new models to the relationships.
Gurmandeep Singh
#models #auditing
#Laravel Tip💡Put this trait on all your models to track easily who created and updated a model.
Jamil Soufan
No articles were found.