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.9k
Laravelにおける後悔しないためのアプリケーション設計
laravel.osaka 2016 で発表したものです。
localdisk
November 02, 2016
Tweet
Share
More Decks by localdisk
See All by localdisk
about Laravel 5.3
localdisk
1
960
Laravel の効率的な学び方
localdisk
9
3.3k
逆引きLaravel
localdisk
7
13k
Other Decks in Programming
See All in Programming
PHPライセンス変更の議論を通じて学ぶOSSライセンスの基礎
matsuo_atsushi
0
140
Honoを技術選定したAI要件定義プラットフォームAcsimでの意思決定
codenote
0
140
CSC509 Lecture 13
javiergs
PRO
0
250
Kotlinで実装するCPU/GPU 「協調的」パフォーマンス管理
matuyuhi
0
370
What’s Fair is FAIR: A Decentralised Future for WordPress Distribution
rmccue
0
160
What's New in Web AI?
christianliebel
PRO
0
120
CSC509 Lecture 11
javiergs
PRO
0
300
Eloquentを使ってどこまでコードの治安を保てるのか?を新人が考察してみた
itokoh0405
0
3.1k
Register is more than clipboard
satorunooshie
1
460
OSS開発者の憂鬱
yusukebe
10
3.3k
組織もソフトウェアも難しく考えない、もっとシンプルな考え方で設計する #phpconfuk
o0h
PRO
10
4k
例外処理を理解して、設計段階からエラーを見つけやすく、起こりにくく #phpconfuk
kajitack
12
5.8k
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
A better future with KSS
kneath
239
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Designing for Performance
lara
610
69k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
Rails Girls Zürich Keynote
gr2m
95
14k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
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ͷ࡞Γํ
࣭ͱ͔ʁ
͓ΘΓ