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
92
地方カンファレンス主催のススメ
bumptakayuki
1
140
Laravelで敢えて試す脆弱性のある書き方
bumptakayuki
1
680
地方でのPHPエンジニア採用って実際どうなの?
bumptakayuki
0
500
沖縄観光、名物を一挙紹介!
bumptakayuki
2
510
Laravel ShiftでLaravelのバージョンアップしてみた話
bumptakayuki
1
1.6k
flutterでイベントアプリを作ってみた
bumptakayuki
0
100
オフショア開発の辛みと学んだ事
bumptakayuki
0
330
ChatGPTにStripeのサンプルコードを書かせてみた
bumptakayuki
1
150
Other Decks in Programming
See All in Programming
Debugging: All you need to know (for simultaneous interpreting)
jmatsu
2
680
Scala アプリケーションのビルドを改善してデプロイ時間を 1/4 にした話 | How I improved the build of my Scala application and reduced deployment time by 4x
nomadblacky
1
170
労務ドメインを快適に開発する方法 / How to Comfortably Develop in the Labor Domain
yuki21
1
250
Ebitengineの1vs1ゲーム WebRTCの活用
ponyo877
0
370
僕が思い描くTypeScriptの未来を勝手に先取りする
yukukotani
9
2.4k
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
530
KSPの導入・移行を前向きに検討しよう!
shxun6934
PRO
0
180
XStateでReactに秩序を与えたい
gizm000
0
720
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
260
The Shape of a Service Object
inem
0
510
Rustではじめる負荷試験
skanehira
5
1.2k
状態管理ライブラリZustandの導入から運用まで
k1tikurisu
3
460
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
221
8.8k
Typedesign – Prime Four
hannesfritz
39
2.3k
Robots, Beer and Maslow
schacon
PRO
157
8.2k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
GraphQLとの向き合い方2022年版
quramy
43
13k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
8.9k
Bash Introduction
62gerente
608
210k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
Facilitating Awesome Meetings
lara
49
5.9k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
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