Recall & Review
beginner
What is a query scope in Laravel?
A query scope is a way to define common query logic inside a model. It lets you reuse query conditions easily by calling a method on the model's query builder.
Click to reveal answer
beginner
How do you define a local query scope in a Laravel model?
Define a method in the model starting with
scope followed by the scope name. For example, scopeActive($query) defines a scope called active. The method receives the query builder as the first argument.Click to reveal answer
beginner
How do you use a local query scope in Laravel when querying?
Call the scope method name without the
scope prefix on the model query. For example, User::active()->get() uses the scopeActive method.Click to reveal answer
intermediate
What is a global query scope in Laravel?
A global query scope automatically adds conditions to all queries for a model. It is useful for things like soft deletes or multi-tenant filtering.
Click to reveal answer
intermediate
How do you remove a global scope from a Laravel query?
Use the <code>withoutGlobalScope()</code> method on the query builder and pass the scope class or name to exclude it from the query.Click to reveal answer
How do you name a local query scope method in a Laravel model?
✗ Incorrect
Local query scopes must start with 'scope' followed by the scope name, like 'scopeActive'.
How do you apply a local query scope named 'active' when querying a model?
✗ Incorrect
You call the scope without the 'scope' prefix: User::active()->get().
What is the main purpose of a global query scope?
✗ Incorrect
Global scopes add conditions automatically to every query on the model.
How can you exclude a global scope from a query?
✗ Incorrect
The method withoutGlobalScope() removes a global scope from the query.
Which argument does a local query scope method receive first?
✗ Incorrect
The first argument is the query builder to modify the query.
Explain how to create and use a local query scope in Laravel.
Think about naming and how you call the scope when querying.
You got /3 concepts.
Describe what a global query scope is and how to remove it from a query.
Consider automatic query changes and how to opt out.
You got /3 concepts.