Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How would I create a scope that can be used by multiple models without polluting the global scope space? This scope would be manually called each time I want to use it.
Example:
$assigns = Assign::dryScope(); $contacts = Contact::dryScope();
Traits
Best way is to use traits. Use appropriate namespacing as needed. ScopeTrait.php
trait ScopeTrait { protected function dryScope() { //Scope definition } } class Assign extends xModel { use ScopeTrait; }
Add a comment
You can create a class that extends the Model, follows a template below:
class xModel extends Model { protected function dryScope() {} } class Assign extends xModel { }
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
Traits