DEV Community

Cover image for Eloquent Query Scope in Laravel
Suresh Ramani
Suresh Ramani

Posted on

Eloquent Query Scope in Laravel

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.

https://techvblogs.com/blog/eloquent-query-scope-laravel

Top comments (0)