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
120
地方カンファレンス主催のススメ
bumptakayuki
1
160
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
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
Jakarta EE meets AI
ivargrimstad
0
140
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
flutterkaigi_2024.pdf
kyoheig3
0
150
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
240
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
ヤプリ新卒SREの オンボーディング
masaki12
0
130
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Featured
See All Featured
Site-Speed That Sticks
csswizardry
0
28
4 Signs Your Business is Dying
shpigford
180
21k
Visualization
eitanlees
145
15k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Unsuck your backbone
ammeep
668
57k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A designer walks into a library…
pauljervisheath
204
24k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
How STYLIGHT went responsive
nonsquared
95
5.2k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
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