Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Eloquent Scope Classes
Search
Jordan Hoff
January 18, 2018
Programming
62
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Eloquent Scope Classes
Presentation from the Laravel Omaha Meetup
January 18th, 2018
Jordan Hoff
Jordan Hoff
January 18, 2018
More Decks by Jordan Hoff
See All by Jordan Hoff
Writing Clean PHP
jhoff
0
120
Other Decks in Programming
See All in Programming
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
640
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
170
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
210
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
APNsからLive Activityを開始する話
yumnumm
0
170
Railsバージョンを4倍にした話
optim
0
350
Featured
See All Featured
From π to Pie charts
rasagy
1
400
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Rails Girls Zürich Keynote
gr2m
96
14k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
It's Worth the Effort
3n
188
29k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Raft: Consensus for Rubyists
vanstee
142
7.8k
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Accessibility Awareness
sabderemane
1
250
ラッコキーワード サービス紹介資料
rakko
1
5.3M
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
What's in a price? How to price your products and services
michaelherold
247
13k
Transcript
ELOQUENT SCOPE CLASSES JORDAN HOFF - LARAVEL OMAHA MEETUP
About Me Software Engineer Dad Baseball Serial Hobbyist
Initial request Veterinary hospital needs a backend system to track
business Users ( employees ) tied to authentication Customers Animals Invoices, Appointments, etc
https://twitter.com/iamdevloper/status/727854065426804738
Animals Employees Customers … Authentication
Then, the plan changes The client decides that they want
more Rebuild their external website Allow customers to login Give customers access to see invoices, schedule appointments, etc
Authentication Animals Employees Customers …
Customers Employees Users
Eloquent Scope Classes Create a base model with it’s own
table Extend base model for each “type” and apply a Global Query Scope Scope classes will behave like an isolated model
None
Things to consider Eloquent is smart. Maybe too smart. Table
names are automatically assumed based on the current class name This applies to not only the model, but relationships as well
None
Add a global scope Override the boot method to register
a scope that will differentiate Remember to call the parent boot method!
None
None
It works!
Gotcha! Relationships defined on the base class may need tables
and keys explicitly defined in order to work properly when called from a scope class context
More information https://tighten.co/blog/extending-models-in-eloquent https://github.com/laravel-omaha/scope_classes