Skip to main content

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

  • 3298
  • Created Aug 2018
  • Updated Jun 2026

Files in this example

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

guillaumebriday/laravel-blog

  • 1800
  • 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

  • 371
  • Created Dec 2018
  • Updated Jun 2026

Files in this example

  • app/Models/ExternalCourse.php
View full example

luadotsh/lua

  • 333
  • Created Oct 2024
  • Updated Apr 2026

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

  • 300
  • Created Nov 2019
  • Updated Mar 2023

Files in this example

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

jcergolj/laravellte

  • 215
  • Created Jan 2020
  • Updated Feb 2023

Files in this example

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

benjamincrozat/blog-v5

  • 131
  • Created Feb 2025
  • Updated Jun 2026

Files in this example

  • app/Models/Metric.php
View full example

OpenLitterMap/openlittermap-web

  • 130
  • Created Aug 2020
  • Updated Jun 2026

Files in this example

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

cattr-app/server-application

  • 93
  • Created Mar 2023
  • Updated Jan 2026

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

  • 38
  • Created Dec 2018
  • Updated Dec 2025

Files in this example

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

mohsin-shaikh/expense-tracker

  • 33
  • 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

  • 18
  • Created Apr 2020
  • Updated Mar 2021

Files in this example

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

archboard/tidal-ptc

  • 5
  • Created Dec 2023
  • Updated Mar 2026

Files in this example

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