Skip to main content

Code Examples of local scopes

Discover how to use Laravel's local scopes method in real-world applications. Browse 18 examples from popular open-source projects.

18 examples
Local scopes allow you to define a common condition for Eloquent models that you may easily re-use throughout your application. For example, you may need to frequently retrieve all users that are considered "popular". To define a scope, create an Eloquent model method like function scopeCondition().
Read more in the official Laravel docs.

bytefury/crater

  • 8295
  • Created Nov 2019
  • Updated Aug 2024

Files in this example

  • app/Models/PaymentMethod.php
    • app/Http/Controllers/V1/Payment/PaymentMethodsController.php
View full example

Kovah/LinkAce

  • 3298
  • Created Aug 2018
  • Updated Jun 2026

Files in this example

  • app/Models/Link.php
    • app/Http/Controllers/App/DashboardController.php
View full example

laravelio/laravel.io

  • 2499
  • Created May 2016
  • Updated Jun 2026

Files in this example

  • app/Models/Thread.php
    • app/Http/Controllers/Forum/ThreadsController.php
View full example

inertiajs/pingcrm

  • 2326
  • Created Mar 2019
  • Updated Feb 2025

Files in this example

  • app/Models/Contact.php
    • app/Http/Controllers/ContactsController.php
View full example

guillaumebriday/laravel-blog

  • 1800
  • Created Dec 2016
  • Updated Oct 2024

Files in this example

  • app/Models/Comment.php
    • app/Http/Controllers/Admin/ShowDashboard.php
View full example

officelifehq/officelife

  • 949
  • Created Jan 2019
  • Updated Jul 2024

Files in this example

  • app/Models/Company/Task.php
    • app/Http/ViewHelpers/Dashboard/DashboardMeViewHelper.php
View full example

ploi-deploy/roadmap

  • 561
  • Created May 2022
  • Updated Jun 2026

Files in this example

  • app/Models/Board.php
    • app/Http/Controllers/ProjectController.php
View full example

protonemedia/eddy-server-management

  • 510
  • Created May 2023
  • Updated Aug 2024

Files in this example

  • app/Models/Credentials.php
    • app/Http/Controllers/ServerController.php
View full example

spatie/spatie.be

  • 499
  • Created Oct 2020
  • Updated Jun 2026

Files in this example

  • app/Models/Ad.php
    • app/Jobs/RandomizeAdsOnGitHubRepositoriesJob.php
View full example

saleem-hadad/finance

  • 449
  • Created Jan 2022
  • Updated Feb 2026

Files in this example

  • app/Models/Transaction.php
    • app/GraphQL/Queries/TotalExpensesTrend.php
View full example

LaravelDaily/Laravel-Support-Ticketing

  • 300
  • Created Nov 2019
  • Updated Mar 2023

Files in this example

  • app/Ticket.php
    • app/Http/Controllers/Admin/TicketsController.php
View full example

christophrumpel/larastreamers

  • 238
  • Created May 2021
  • Updated Mar 2026

Files in this example

  • app/Models/Stream.php
    • app/Http/Controllers/PageHomeController.php
View full example

PHPJunior/mtube

  • 143
  • Created Jul 2021
  • Updated Mar 2023

Files in this example

  • app/Models/Channel/Comment.php
    • app/Http/Livewire/Frontend/Components/Comment.php
View full example

benjamincrozat/blog-v5

  • 131
  • Created Feb 2025
  • Updated Jun 2026

Files in this example

  • app/Models/Link.php
    • app/Http/Controllers/Links/ListLinksController.php
View full example

alkrauss48/simple-slides

  • 98
  • Created Nov 2023
  • Updated Feb 2026

Files in this example

  • app/Models/DailyView.php
    • app/Filament/Widgets/ViewStats.php
View full example

crivion/laraboard-careers

  • 81
  • Created Jul 2022
  • Updated May 2023

Files in this example

  • app/Models/Job.php
    • app/Http/Controllers/Front/HomepageController.php
View full example

driesvints/driesvints.com

  • 73
  • Created May 2020
  • Updated Jun 2026

Files in this example

  • app/Models/Post.php
    • app/Http/Controllers/BlogController.php
View full example

nabilhassen/larasense

  • 63
  • Created Nov 2024
  • Updated Jun 2026

Files in this example

  • app/Models/Publisher.php
    • app/Console/Commands/LarasenseBotCommand.php
View full example