Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eloquent\Model: identify scopeable cases #11

Open
rentalhost opened this issue May 31, 2017 · 0 comments
Open

Eloquent\Model: identify scopeable cases #11

rentalhost opened this issue May 31, 2017 · 0 comments
Milestone

Comments

@rentalhost
Copy link
Owner

rentalhost commented May 31, 2017

Laravel query scopes are preferable over where() and similar methods. Then when we find methods like that outside a scope method, suggests to transform it to a scope method.

$userQuery = User::query();
$userQuery->where('age', '>=', 18);

return $userQuery->first();

In this case, where('age', ...) should be transformed to a scope method: (eg. User.php)

public function scopeFilterAge(Builder $builder, $age)
{
    $builder->where('age', '>=', $age);
}

Then:

$userQuery = User::query();
$userQuery->filterAge(18);

return $userQuery->first();
@rentalhost rentalhost added this to the 1.0.0+ milestone May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant