0

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();
1
  • 1
    That's the only way, global scopes. You may want to play with Traits Commented Aug 24, 2017 at 0:32

2 Answers 2

4

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;

}
Sign up to request clarification or add additional context in comments.

1 Comment

Used a trait. Thanks.
1

You can create a class that extends the Model, follows a template below:

class xModel extends Model
{

    protected function dryScope() {}

}


class Assign extends xModel
{

}

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.