Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Eloquent Scope Classes
Search
Jordan Hoff
January 18, 2018
Programming
61
1
Share
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
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
310
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
910
今さら聞けないCancellationToken
htkym
0
220
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
190
CSC307 Lecture 17
javiergs
PRO
0
310
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
140
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
2
240
net-httpのHTTP/2対応について
naruse
0
430
AIとRubyの静的型付け
ukin0k0
0
530
AIエージェントの隔離技術の徹底比較
kawayu
0
460
関係性から理解する"同一性"の型用語たち
pvcresin
2
630
Featured
See All Featured
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Fireside Chat
paigeccino
42
3.9k
A better future with KSS
kneath
240
18k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
220
Become a Pro
speakerdeck
PRO
31
6k
Agile that works and the tools we love
rasmusluckow
331
21k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
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