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
840
地方でのPHPエンジニア採用って実際どうなの?
bumptakayuki
0
550
沖縄観光、名物を一挙紹介!
bumptakayuki
2
560
Laravel ShiftでLaravelのバージョンアップしてみた話
bumptakayuki
1
1.9k
flutterでイベントアプリを作ってみた
bumptakayuki
0
120
オフショア開発の辛みと学んだ事
bumptakayuki
0
350
ChatGPTにStripeのサンプルコードを書かせてみた
bumptakayuki
1
180
Other Decks in Programming
See All in Programming
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
740
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
270
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
370
ドメインイベント増えすぎ問題
h0r15h0
2
300
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
Symfony Mapper Component
soyuka
2
730
たのしいparse.y
ydah
3
120
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Practical Orchestrator
shlominoach
186
10k
Site-Speed That Sticks
csswizardry
2
190
The World Runs on Bad Software
bkeepers
PRO
65
11k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
RailsConf 2023
tenderlove
29
940
Optimizing for Happiness
mojombo
376
70k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Typedesign – Prime Four
hannesfritz
40
2.4k
It's Worth the Effort
3n
183
28k
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