Laravel Pro Tips
🔥 Laravel Tip: use scopes to make your code more readable.
You can even combine multiple scopes. It's an awesome feature!.
Laravel Tip: Very often you need to filter the Model records based on created_date.
👉You can create scope Methods after() and before() and use them like below.
🔥 If multiple of your Models needs these methods, you can move them to Trait.
The Laravel Dev
🔥 #Laravel Tip: Make use of local scopes in your Eloquent models in order to make your queries much easier to understand at a glance.
🌶️ #Laravel Tip: Favour a more declarative coding style by using Eloquent Query Scopes.
Scopes make your code more meaningful and semantic 👌
#PHP #Developers #coding
Bilal Haidar - Available 4 Laravel gigs
🔥 #Laravel Tip: Data leakage from incorrectly scoped queries is a major problem. One way of reducing the risk of it happening, is to always define and use relationship methods on your models. That way they will be automatically scoped.
🔥 Eloquent scopes pair very well with complex relation queries
Scopes should also have @method annotations. They make the model more self-documenting & better supported in IDEs
🔥 #Laravel Tip: If you find yourself adding the same set of conditions to a query again and again, consider reaching for a local scope. It's a great way to keep things clean and makes your code more reusable.
No articles were found.