DEV Community

Cover image for Eloquent Query Scope in Laravel

Eloquent Query Scope in Laravel

Suresh Ramani
I am working on Laravel, Vue.js, React.js ( Learning ), and a little bit familiar with Node.js,, and MongoDB. and I am do all stuff on Ubuntu so I familiar with Linux Operating System.
・1 min read

Laravel Eloquent Queries are the Best one. We are used. Eg: Post::all(); this returns all records. But we need to build our custom queries and use that where we want. So here Laravel provides a solution. That call Model Scope.

If you are writing eloquent queries in your Laravel project and write the same logic in your queries repeatedly, then query scopes might be of use to you. Laravel provides a solution for wrapping your conditions into a readable and reusable statement called Scopes.

Laravel has two scopes: Local Scope and Global Scope.

This article only discusses Local Scopes.

Discussion (0)

Forem Open with the Forem app