intermediateLaravel
Previous
What is attribute casting?
Next
What is the difference between find(), first(), firstOrFail(), and findOrFail()?
What are local and global query scopes?
Answer
Clear, interview-ready explanation
A local scope is a reusable query constraint defined on one model and called explicitly, such as an active scope that adds a where condition. It keeps frequently used filtering logic readable and consistent without duplicating query clauses.
A global scope is applied automatically to every query for a model. It is appropriate for a universal constraint such as excluding soft-deleted records or enforcing tenant visibility. Because global scopes affect every query, developers need a deliberate way to remove or bypass them for trusted administrative or reporting cases.