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のFat Controllerをどうリファクタしていくか
Search
Takayuki
August 25, 2021
Programming
0
1.1k
LaravelのFat Controllerをどうリファクタしていくか
LaravelのFat Controllerをどうリファクタしていくか
Takayuki
August 25, 2021
Tweet
Share
More Decks by Takayuki
See All by Takayuki
エンジニアのキャリア論
bumptakayuki
0
110
地方カンファレンス主催のススメ
bumptakayuki
1
150
Laravelで敢えて試す脆弱性のある書き方
bumptakayuki
1
790
地方でのPHPエンジニア採用って実際どうなの?
bumptakayuki
0
530
沖縄観光、名物を一挙紹介!
bumptakayuki
2
540
Laravel ShiftでLaravelのバージョンアップしてみた話
bumptakayuki
1
1.8k
flutterでイベントアプリを作ってみた
bumptakayuki
0
110
オフショア開発の辛みと学んだ事
bumptakayuki
0
340
ChatGPTにStripeのサンプルコードを書かせてみた
bumptakayuki
1
170
Other Decks in Programming
See All in Programming
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
C++でシェーダを書く
fadis
6
4.1k
CSC509 Lecture 11
javiergs
PRO
0
180
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
Jakarta EE meets AI
ivargrimstad
0
600
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
890
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Jakarta EE meets AI
ivargrimstad
0
140
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
RubyLSPのマルチバイト文字対応
notfounds
0
120
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Code Reviewing Like a Champion
maltzj
520
39k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
BBQ
matthewcrist
85
9.3k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
How to Ace a Technical Interview
jacobian
276
23k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Transcript
LaravelͷFat ControllerΛͲ͏ ϦϑΝΫλ͍͔ͯ͘͠
3 LaravelͰͷϦϑΝΫλํ Agenda 2 ϓϩδΣΫτͷ 1 ࣗݾհ 4 ϦϑΝΫλ༰
1 ࣗݾհ
4 ࣗݾհ ◆໊લ ླ ೭(Suzuki Takayuki) ◆ࣗݾհ ɾ1990ɺਆಸݝੜ·Εɻ ɾࣾձਓʹͳ͔ͬͯΒɺϓϩάϥϛϯάΛ࢝ΊΔɻ ɾ2015ʹϑϧεϐʔυʹೖࣾ͠ɺ2017ʹϑϦʔϥ
ϯεΛͬͨޙʹ201711݄ʹԭೄͰىۀɻ ◆झຯ ίεϓϨɺԻָϥΠϒɺϚϥιϯେձʹग़Δɺٿ؍ ઓ ◆Twitter @kanbo0605
Copyright Re:Build.inc All Rights Reserved. ࣗݾհ 1
Copyright Re:Build.inc All Rights Reserved. ձࣾհ 1 ◆ձ໊ࣾ גࣜձࣾRe:Build ◆ॅॴ
ԭೄݝಹࢢٱໜ2-2-2 λΠϜεϏϧ ◆ࣄۀ༰ ɾࣗࣾWEBαʔϏεͷاըɾ։ൃɻ ɾडୗ։ൃ ◆ࣾһ 10໊ ◆ΤϯδχΞͷಇ͖ํ ϦϞʔτϫʔΫՄೳͳࣗ༝ͳಇ͖ํΛਪͯ͠·͢ʂ
Copyright Re:Build.inc All Rights Reserved. ࣗݾհ 1
Copyright Re:Build.inc All Rights Reserved. ࣗݾհ 1
Copyright Re:Build.inc All Rights Reserved. 9 ɾαʔϏε໊ Tadoru https://tadoru.work/
ɾγεςϜ֓ཁ ΤϯδχΞಛԽܕͷ ϦϑΝϥϧ Ϋϥυιʔγϯά 1 ձࣾհ
Copyright Re:Build.inc All Rights Reserved. 1 0 ɾαʔϏε໊ Re:Build Boot
Camp https://rebuild-bootcamp.jp/ ɾ֓ཁ ԭೄͱٶ࡚Ͱʮ࣮ϨϕϧʯΛ ࢦ͢ํ͚ͷϓϩάϥϛϯάε Ϋʔϧ ɾ͏ٕज़ LaravelɺVue.jsͳͲ 1 ձࣾհ
Copyright Re:Build.inc All Rights Reserved. 11 ࣮Ϩϕϧ ॳ৺ऀ ॳڃऀ ํͷॳ৺ऀ͚ͷϓϩάϥ
ϛϯάεΫʔϧΛଔۀͨ͠ޙ ͷॳڃऀ͔Β࣮Ϩϕϧ·Ͱ ͷؒΛຒΊΔεΫʔϧ 1 ձࣾհ
1 2 ͜ͷൃදͷରऀ ɾLaravelΛ࣮Ͱ͍࢝Ίͨਓ ɾϓϩδΣΫτ͕େ͖͘ͳ͖ͬͯͯɺίʔυͷཧͰΜͰ͍Δਓ ɾϓϩδΣΫτͰίʔσΟϯάن͕ͳͯ͘ࠔ͍ͬͯΔ
2 ϓϩδΣΫτͷ
1 4 2 ϓϩδΣΫτͷ ɾ͓ͦΒ͘ɺJavaग़ͷLaravelॳ৺ऀΛ͔͖ूΊ ͨঢ়ଶ ɾίʔυϨϏϡʔແ͠ ɾίʔσΟϯάنແ͠ ɾಈ͚ྑ͍ঢ়ଶ ɾ΄΅༷ॻແ͠
1 5 2 ίʔυͷओͳ Կ͔ҰͭίʔυΛ͍ͬͨ͡ΒɺσάϨ͍͢͠δΣ ϯΨঢ়ଶ ɾPHPUnitͷςετ͕Ұͭͳ͍ ɾϚδοΫφϯόʔ͕େྔʹΘΕ͍ͯΔ ɾifจͷωετ(5ॏͱ͔) ɾࣈ͕stringͱnumberͰೖͬͯ͘Δ
ɾఆ͕΄΅ΘΕ͍ͯͳ͍ ɾSQL͕ॻ͖
3 LaravelͰͷϦϑΝΫλํ
1 7 Fat Controller ͱʁ ɾFatControllerʢଠͬͨίϯτϩʔϥʣͷ͜ͱͰ͢ɻͳΜͰଠΔ͔ͱݴ͏ͱ୲͏͕ଟ͍ ͔ΒͰ͢ɻྫ͑ɺԼهͷΑ͏ͳཧ༝͕ߟ͑ΒΕ·͢ɻ ɾෳͷϝιουͰॲཧ͕ॏෳ͍ͯ͠Δɻ ɾ୯७ʹΞΫγϣϯϝιου͕ଟ͍ɻ ɾϩδοΫ͕ଟ͗͢Δɻ
ɾͻͱͭͷมߋ͕ଞͷ෦ʹٴ΅͢ӨڹΛݕͮ͠Β͍ঢ়ଶʹ͋Δ
1 8 Fat ControllerԿͰྑ͘ͳ͍ͷ͔ʁ ɾControllerͷͷൣғ֎ͷॲཧೖ͖ͬͯͯ͠·͏ɻ Controllerͷ - ೖྗʢHTTPϦΫΤετʣΛड͚औΓɺνΣοΫ͢Δ - దͳॲཧܥΛ͢
- ϨεϙϯεΛฦ͢ ͷ̏ͭͱݴΘΕ͍ͯ·͢ɻ ɾҰͭҰͭͷॲཧ͕ͯ͘ɺॲཧΛ͏ͷ͕͍͠ɻ ɾॲཧͷॏෳ͕ଟ͍ͷͰɺ༷มߋ͕͋ͬͨ࣌ʹमਖ਼͕͍͠ɻ https://eh-career.com/engineerhub/entry/2021/05/28/160000#Laravel%E3%81%AE%E4%BE%8B%E3%81%AB%E8%A6%8B%E3%82%8BFatModel
શମߏ(ཧ) αʔόαΠυ ϒϥβ͔Β ΞΫηε Component HTML CSS JS bladeͳͲ Resouce.php
APIϦΫΤετ APIϨεϙϯε Request.php router controller Model Database όϦσʔγϣϯ ϨεϙϯεΛ ఆٛ Service αʔυύʔςΟ MPA Events Enum ਵ࣌༻
શମߏ(ཧ) αʔόαΠυ ϒϥβ͔Β ΞΫηε Component HTML CSS JS bladeͳͲ Resouce.php
APIϦΫΤετ APIϨεϙϯε Request.php router controller Model Database όϦσʔγϣϯ ϨεϙϯεΛ ఆٛ Service αʔυύʔςΟ MPA Events Enum ਵ࣌༻ ControllerͰग़͖ͯ ͨϩδοΫΛmodel ʹدͤΔ
શମߏ(ཧ) αʔόαΠυ ϒϥβ͔Β ΞΫηε Component HTML CSS JS bladeͳͲ Resouce.php
APIϦΫΤετ APIϨεϙϯε Request.php router controller Model Database όϦσʔγϣϯ ϨεϙϯεΛ ఆٛ Service αʔυύʔςΟ MPA Events Enum ਵ࣌༻ ֎෦αʔϏεΛୟ͘ Α͏ͳॲཧService ʹॻ͘
શମߏ(ཧ) αʔόαΠυ ϒϥβ͔Β ΞΫηε Component HTML CSS JS bladeͳͲ Resouce.php
APIϦΫΤετ APIϨεϙϯε Request.php router controller Model Database όϦσʔγϣϯ ϨεϙϯεΛ ఆٛ Service αʔυύʔςΟ MPA Events Enum ਵ࣌༻ DBͰఆٛ͢Δ΄ͲͰ ͳ͍Α͏ͳఆܥ Enumʹॻ͘
શମߏ(ཧ) αʔόαΠυ ϒϥβ͔Β ΞΫηε Component HTML CSS JS bladeͳͲ Resouce.php
APIϦΫΤετ APIϨεϙϯε Request.php router controller Model Database όϦσʔγϣϯ ϨεϙϯεΛ ఆٛ Service αʔυύʔςΟ MPA Events Enum ਵ࣌༻ ό Ϧ σ ʔ γ ϣ ϯ RequestΫϥεʹॻ͘
શମߏ(ͬͱେنʹͳ͖ͬͯͨΒ) αʔόαΠυ ϒϥβ͔Β ΞΫηε Component HTML CSS JS bladeͳͲ Resouce.php
APIϦΫΤετ APIϨεϙϯε Request.php router controller Model όϦσʔγϣϯ ϨεϙϯεΛ ఆٛ Service αʔυύʔςΟ MPA Events Enum ਵ࣌༻ Repository Logic Ϗδωεɾ ϩδοΫ σʔλɾ ΞΫηε Database
4 ϦϑΝΫλ༰
2 6 ᶃϚδοΫφϯόʔΛఆͰఆٛ͢Δ ϚδοΫφϯόʔΛmodel͘͠ EnumΫϥεʹఆͱͯ͠ఆٛͯ͠ ݺͼग़͢ɻ
2 7 ᶄprivateϝιουʹΓ͚Δ Ұͭͷϝιου͕50ߦΛ͑ͦ͏ͳ Βɺॲཧ͝ͱʹprivateϝιουʹ ͚Δ
2 8 ᶅmodelΫϥεʹϩδοΫΛ͚Δ ControllerʹϩδοΫ͕૿͖͑ͯͨ ΒɺmodelʹॲཧΛ͚Δ
2 9 ᶆόϦσʔγϣϯRequestΫϥεʹॻ͘ ControllerʹόϦσʔγϣϯΛॻ ͖͠ͳ͍ͰRequestΫϥεͰॲཧ͢ Δ
3 0 ᶇෳͷ Controller ʹ͢Δ ҰͭͷControllerͰΞΫγϣϯϝ ι ο υ ͕
૿ ͑ ͢ ͗ Δ ߹ ɺ ControllerϑΝΠϧ͝ͱ͚Δ
3 1 ᶈϨεϙϯεͷσʔλΛResource ʹॻ͘ Ϩεϙϯεσʔλ͕ෳࡶԽ͖ͯͨ͠ ΓɺՃ͕ඞཁͳ߹ResouceΫ ϥεʹ͚Δ
3 2 ·ͱΊ ɾControllerͷͷൣғ֎ͷॲཧೖΕͳ͍ɻ ɾඞཁʹԠͯ͡ɺϩδοΫͷΛ૿͢ɻ ɾॲཧΛࡉԽͯ͠ɺॏෳ͢Δॲཧ·ͱΊΔɻ
3 3 ࢀߟ https://qiita.com/karayok/items/d7740ab2bd0adbab2e06 https://qiita.com/nunulk/items/2323b0c30a2cbe5fdb0c https://qiita.com/nunulk/items/6ed409345efb6ee4f660 ϦϙδτϦύλʔϯͱ Laravel ΞϓϦέʔγϣϯͰͷσΟϨΫτϦߏ ࠓ͔Β࢝ΊΒΕΔϦϑΝΫλϦϯά10બ
(1) Laravel Ͱ Fat Controller Λ͙ 5 ͭͷ Tips