Skip to content

Commit f7cfde2

Browse files
committed
Add chaining example to the Query Scope section
I first learned this from [a comment](laravel/framework#273 (comment)) on PR. This great feature should be documented!
1 parent db2836e commit f7cfde2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

eloquent.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,17 @@ Scopes allow you to easily re-use query logic in your models. To define a scope,
305305
{
306306
return $query->where('votes', '>', 100);
307307
}
308+
309+
public function scopeWomen($query)
310+
{
311+
return $query->whereGender('W');
312+
}
308313

309314
}
310315

311316
**Utilizing A Query Scope**
312317

313-
$users = User::popular()->orderBy('created_at')->get();
318+
$users = User::popular()->women()->orderBy('created_at')->get();
314319

315320
**Dynamic Scopes**
316321

0 commit comments

Comments
 (0)