laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Apply Scope to Query Builder #2588

Closed lamtranb closed 3 years ago

lamtranb commented 3 years ago

Hello,

Laravel has:

My problem is:

Example:

$exampleScope = new ExampleScope();
$exampleScope->setSomething('123');

$model = new Model();
$data = $model->newQuery()->applyScope($exampleScope)->get();

But I can make a macro to achieve this. How do you guys think about this?

Hope you guys could support me this issue. Many thanks.

themsaid commented 3 years ago

You can use the withGlobalScope() method.