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
130
地方カンファレンス主催のススメ
bumptakayuki
1
170
Laravelで敢えて試す脆弱性のある書き方
bumptakayuki
1
870
地方でのPHPエンジニア採用って実際どうなの?
bumptakayuki
0
570
沖縄観光、名物を一挙紹介!
bumptakayuki
2
570
Laravel ShiftでLaravelのバージョンアップしてみた話
bumptakayuki
1
2k
flutterでイベントアプリを作ってみた
bumptakayuki
0
120
オフショア開発の辛みと学んだ事
bumptakayuki
0
350
ChatGPTにStripeのサンプルコードを書かせてみた
bumptakayuki
1
180
Other Decks in Programming
See All in Programming
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
420
2025.01.17_Sansan × DMM.swift
riofujimon
2
550
rails newと同時に型を書く
aki19035vc
5
710
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.1k
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
300
Azure AI Foundryのご紹介
qt_luigi
1
190
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
560
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
420
Beyond ORM
77web
11
1.6k
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
0
100
ErdMap: Thinking about a map for Rails applications
makicamel
1
610
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.3k
GitHub's CSS Performance
jonrohan
1030
460k
Bash Introduction
62gerente
610
210k
Thoughts on Productivity
jonyablonski
68
4.4k
How to train your dragon (web standard)
notwaldorf
89
5.8k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
The Pragmatic Product Professional
lauravandoore
32
6.4k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
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