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
Laravelにおける後悔しないためのアプリケーション設計
Search
localdisk
November 02, 2016
Programming
8
5.7k
Laravelにおける後悔しないためのアプリケーション設計
laravel.osaka 2016 で発表したものです。
localdisk
November 02, 2016
Tweet
Share
More Decks by localdisk
See All by localdisk
about Laravel 5.3
localdisk
1
890
Laravel の効率的な学び方
localdisk
9
3.2k
逆引きLaravel
localdisk
7
13k
Other Decks in Programming
See All in Programming
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
1k
Missing parts when designing and implementing Android UI
ericksli
0
310
我々のデザインシステムは Chakra v3 にアップデートします
shunya078
2
990
Reckoner における Datadog Browser Test の活用事例 / Datadog Browser Test at Reckoner
nomadblacky
0
110
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
370
Realtime API 入門
riofujimon
0
160
flutterkaigi_2024.pdf
kyoheig3
0
230
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
みんなでプロポーザルを書いてみた
yuriko1211
0
290
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
140
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
2.2k
初めてDefinitelyTypedにPRを出した話
syumai
0
450
Featured
See All Featured
Docker and Python
trallard
40
3.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
160
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Documentation Writing (for coders)
carmenintech
65
4.4k
Code Reviewing Like a Champion
maltzj
520
39k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Thoughts on Productivity
jonyablonski
67
4.3k
Music & Morning Musume
bryan
46
6.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Transcript
Laravelʹ͓͚Δ ޙչ͠ͳ͍ͨΊͷ ΞϓϦέʔγϣϯઃܭ Laravel Osaka 2016 @localdisk
ࣗݾհ দඌେ ·͓ͭ·͞Δ EEE ΤϯδχΞ Πϊϕʔλʔδϟύϯॴଐ ΤϯδχΞɾσβ ΠφɾσΟϨΫλΛืूத ධൃചத
@localdisk
ืूͯ͠·͢ʂʂʂ
ޙչ͠ͳ͍ΞϓϦέʔγϣϯઃܭ ͱ?
όάΛग़͞ͳ͍།Ұͷํ๏ϓϩάϥϜΛॻ͔ͳ͍͜ͱͩ ʕϓϩάϥϚͷ֨ݴʕ
ͦ͏͍͏Θ͚ʹ͍͔ͳ͍
ݱ࣮ݫ͍͠
ଥڠͯ͠ γϯϓϧ͞Λͨͭ
• ޙչ͠ͳ͍ͨΊʹͲ͏͢Δ͔? • FacadeΛ߇͑ͯΈΔ • Named Routes • FormRequest •
ControllerͰEloquentͷϝιουνΣΠϯېࢭ • Repository Pattern Agenda
FacadeΛ߇͑ͯΈΔ
• ੩తϝιουͷΑ͏ʹ͑Δ • ࣮ࡍαʔϏείϯςφ͔ΒऔΓग़͍ͯ͠Δ • Ͳ͔͜ΒͰ͑Δ • ViewͷதͰ • \Auth::check()
• ݁ՌɺΫϥεͷ͕େ͖͘ͳΔ Facade ศར͚ͩͲ…
https://readouble.com/laravel/5.3/ja/facades.html#facade-class-reference DIΛ͓͏
ͳΔ͘ Contract ͓͏ DIΛ͓͏(2)
• Facade Λ͏͔ΘΓʹ DI Λ͢Δͱ༻͢Δͱ ϝιουͷҾʹ༻͢ΔΫϥε͕ฒͿ • ͋ɺ͍ɻͱΘ͔Δɻ • FacadeΛܦ༝͠ͳ͍ͷͰएׯૣ͘ͳΔ
ͳͥ DI ͔?
Named Routes
• Routeʹ໊લΛ͚ͭΔ • route(‘osaka’); ͰURL͕औಘͰ͖Δ • URL͕มΘͬͯ҆৺ Named Routes
FormRequest
গͣͭ͠هड़ྔ͕ݮ͍ͬͯΔ ͔͠͠ϊΠζʹͳ͍ͬͯΔͷ൱Ίͳ͍ Validation ͷมભ
• php artisan make:request Ϋϥε໊ • rulesϝιουΛ࣮ FormRequest
• ControllerͰϝιουΠϯδΣΫγϣϯ͢Δ͚ͩ • ϊΠζ͕ফ͑ͯϩδοΫʹूதͰ͖Δ FormRequest
ControllerͰEloquentͷ ϝιουνΣΠϯېࢭ
Model Binding
ʮಉ݁͡ՌΛAPIͰฦͤΔΑ͏ʹ͠ͱ͍ͯͶʯ ͱݴΘΕͨΒ…ʁ ControllerͰϝιουνΣΠϯμϝʂ
ModelʹΫΤϦΛด͡ࠐΊΔ
Repository Pattern
• Eloquent User::find ͷΑ͏ʹ੩తʹݺ ·͕͢ɺFacadeͰͳ͍ɻ • ΑͬͯshouldRecieveͱ͍͏ϝιουଘࡏ͠ ͳ͍ • EloquentDBʹґଘ͍ͯ͠Δ
• ςετ͕ࠔΔ ͳͥ Repository Pattern?
• ΠϯλʔϑΣʔεΛఆٛ Repository Patternͷ࡞Γํ
• ΠϯλʔϑΣʔεΛ࣮ɻ͋ͱίϯτϩʔϥͰΠ ϯδΣΫγϣϯ͢Δ Repository Patternͷ࡞Γํ
࣭ͱ͔ʁ
͓ΘΓ