Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Code Examples of global scopes

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

14 examples
Global scopes allow you to add conditions to ALL queries for a particular Model. For example, if you want all records to be always ordered in a certain way.
Read more in the official Laravel docs.

Kovah/LinkAce

  • 3159
  • Created Aug 2018
  • Updated Nov 2025

Files in this example

  • app/Scopes/OrderNameScope.php
    • app/Models/LinkList.php
View full example

guillaumebriday/laravel-blog

  • 1797
  • Created Dec 2016
  • Updated Oct 2024

Files in this example

  • master/app/Scopes/PostedScope.php
    • app/Models/Post.php
View full example

academico-sis/academico

  • 338
  • Created Dec 2018
  • Updated Nov 2025

Files in this example

  • app/Models/ExternalCourse.php
View full example

luadotsh/lua

  • 324
  • Created Oct 2024
  • Updated Oct 2025

Files in this example

  • app/Models/Scopes/MediaScope.php
    • https://github.com/luadotsh/lua/blob/main/app/Models/Media.php
View full example

LaravelDaily/Laravel-Support-Ticketing

  • 294
  • Created Nov 2019
  • Updated Mar 2023

Files in this example

  • app/Scopes/AgentScope.php
    • app/Ticket.php
View full example

jcergolj/laravellte

  • 216
  • Created Jan 2020
  • Updated Feb 2023

Files in this example

  • app/Scopes/VisibleToScope.php
    • app/Models/User.php
View full example

benjamincrozat/blog-v5

  • 126
  • Created Feb 2025
  • Updated Nov 2025

Files in this example

  • app/Models/Metric.php
View full example

OpenLitterMap/openlittermap-web

  • 122
  • Created Aug 2020
  • Updated Nov 2025

Files in this example

  • app/Models/User/User.php
View full example

cattr-app/server-application

  • 87
  • Created Mar 2023
  • Updated Jan 2025

Files in this example

  • app/Scopes/UserAccessScope.php
    • app/Models/User.php
      • tests/Feature/Users/ListTest.php
View full example

Senither/ShareX-Media-Server

  • 43
  • Created Oct 2016
  • Updated Mar 2023

Files in this example

  • app/Scopes/UserScope.php
    • app/Traits/BelongsToUser.php
      • app/Models/Url.php
View full example

ammannbe/RecipeManager

  • 37
  • Created Dec 2018
  • Updated Feb 2023

Files in this example

  • app/Models/OrderByNameScope.php
    • app/Models/Ingredients/Unit.php
View full example

mohsin-shaikh/expense-tracker

  • 31
  • Created Jan 2022
  • Updated Apr 2023

Files in this example

  • app/Scopes/UserVisibilityScope.php
    • app/Models/Category.php
View full example

JuanDMeGon/Laravel-from-Scratch

  • 17
  • Created Apr 2020
  • Updated Mar 2021

Files in this example

  • app/Scopes/AvailableScope.php
    • app/Product.php
View full example

archboard/tidal-ptc

  • 4
  • Created Dec 2023
  • Updated Sep 2025

Files in this example

  • app/Models/Scopes/SchoolScope.php
    • app/Traits/ScopedToSchool.php
      • app/Models/Batch.php
View full example

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.