29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Eloquent: Getting Started 442<br />

.<br />

27 }<br />

28 }<br />

Utilizing A Query Scope<br />

Once the scope has been defined, you may call the scope methods when querying the model.<br />

However, you do not need to include the scope prefix when calling the method. You can even chain<br />

calls to various scopes, for example:<br />

.<br />

1 $users = App\User::popular()->women()->orderBy('created_at')->get();<br />

Dynamic Scopes<br />

Sometimes you may wish to define a scope that accepts parameters. To get started, just add your<br />

additional parameters to your scope. Scope parameters should be defined after the $query argument:<br />

.<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!