Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2021 Web アプリフレームワーク入門_REST API 入門

A518abbe059ea4d68518835f496f425e?s=47 kumaki
June 14, 2021

2021 Web アプリフレームワーク入門_REST API 入門

GTB2020 Web App Framework and REST API Introduction

A518abbe059ea4d68518835f496f425e?s=128

kumaki

June 14, 2021
Tweet

Transcript

  1. GTB2021 WebΞϓϦέʔγϣϯ ϑϨʔϜϫʔΫೖ໳ / REST API ೖ໳

  2. ԕ౻ ଠಙʢenduʣ ॴଐɿ GMOϖύϘגࣜձࣾ ECࣄۀ෦ άʔϖάϧʔϓ ೖࣾɿ 2017೥ झຯɿ ήʔϜɺࣗਬɺϐΞϊ

    ߨࢣ঺հ 2
  3. ຀໺ ߂޾ʢkumak1ʣ ॴଐɿ GMOϖύϘגࣜձࣾ ECࣄۀ෦ Χϥʔϛʔγϣοϓάϧʔϓ ೖࣾɿ 2014೥ झຯɿ ήʔϜΛ࡞ΔɾֆΛඳ͘

    ߨࢣ঺հ 3
  4. ߴڮ ๜඙ʢkunitʣ ॴଐɿ GMOϖύϘגࣜձࣾ ϗεςΟϯάࣄۀ෦ ೖࣾɿ 2018೥ झຯɿ ཱྀߦɺΧϝϥ ߨࢣ঺հ

    4
  5. ๬݄ ᚸتʢmochikoʣ ॴଐɿ GMOϖύϘגࣜձࣾ ϗεςΟϯάࣄۀ෦ ೖࣾɿ 2019೥ झຯɿ F1؍ઓɺβɾΫϩϚχϤϯζɺ ΧϨʔʢΛ৯΂Δʣ

    ߨࢣ঺հ 5
  6. खౡɹঘਓʢ@tositeʣ ॴଐɿ GMOϖύϘגࣜձࣾ ϗεςΟϯάࣄۀ෦ ೖࣾɿ 2018೥ झຯɿ υϥΠϒɾΩϟϯϓɾྉཧ ߨࢣ঺հ 6

  7. ڮޱɹ޼ ॴଐɿ GMOΠϯλʔωοτגࣜձࣾ γεςϜຊ෦ɹ ໊͓લ.com ։ൃ෦ ໊͓લϑϩϯτΤϯυ νʔϜ ೖࣾɿ 2019೥

    झຯɿ ےτϨɺα΢φɺΞχϝ ߨࢣ঺հ 7
  8. ߨٛͷਐΊํʹ ͍ͭͯ

  9. 1೔໨ʢ2021/05/12 16:15ʙ18:40ʣ ࠲ֶ 1࣌ؒ15෼ (16:15ʙ17:30) kumak1 - Webʹ͍ͭͯ - ϖʔδ͕දࣔ͞ΕΔ·Ͱ

    - WebΞϓϦέʔγϣϯʹ͍ͭͯ - WebΞϓϦέʔγϣϯΛ࡞੒͢Δʹ͋ͨͬͯ ։ൃ؀ڥߏங 1࣌ؒ (17:40ʙ18:40) endu - ConoHa VPSʹαʔόʔΛ௥Ճ͢Δ - VSCodeͷ֦ுػೳRemote-SSHͰαʔόʔʹΞΫηε͢Δ ߨٛͷਐΊํʹ͍ͭͯ 9 εέδϡʔϧͱ୲౰ʹ͍ͭͯ
  10. εέδϡʔϧͱ୲౰ʹ͍ͭͯ 2೔໨ʢ2021/05/13 10:30ʙ18:45ʣ Laravelʹ͍ͭͯ 1࣌ؒʢ10:30ʙ11:30ʣ kumak1 - Laravelͱ͸ʁ - Laravelͷศརػೳ

    - LaravelͷσΟϨΫτϦߏ੒ - LaravelͰͷॲཧͷྲྀΕΛ֬ೝ͢Δ ߨٛͷਐΊํʹ͍ͭͯ 10
  11. εέδϡʔϧͱ୲౰ʹ͍ͭͯ 2೔໨ʢ2021/05/13 10:30ʙ18:45ʣ LaravelΛ࢖ͬͯAPIΛ࡞੒͢Δ 6࣌ؒʢ11:40ʙ18:45ʣ endu - ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏ - ΞϓϦέʔγϣϯΛϒϥ΢β͔ΒݟͯΈΑ͏

    - APIͷCRUDΛ࣮૷͠Α͏ - ORMͷΑ΋΍·࿩ - ValidationΛ࣮૷͠Α͏ ߨٛͷਐΊํʹ͍ͭͯ 11
  12. ࣭໰ํ๏ʹ͍ͭͯ جຊ͸zoomͷνϟοτʹॻ͖ࠐΜͰ͍ͩ͘͞ɻ ྫ ʲ࣭໰ʳ***ͱॻ͍ͯΈͨͷͰ͕͢ɺಈ͔ͳ͍Ͱ͢ɻ ʲ࣭໰ʳ*** ͬͯɺͲ͏͍͏ҙຯͰ͠ΐ͏͔? ʲ࣭໰ʳΛݟͯαϒߨࢣ͕࣭໰ʹνϟοτ্Ͱ౴͑·͢ɻ ߨٛͷਐΊํʹ͍ͭͯ 12

  13. ϦΞΫγϣϯʹ͍ͭͯ ࡞ۀύʔτͷਐḿΛ֬ೝ͢ΔͨΊʹօ͞Μͷ൓ԠΛ࢕͏͕࣌͋Γ·͢ɻ ͦͷ࣌͸zoomͷʮखΛڍ͛ΔʯػೳͰϘλϯΛԡ͍ͯͩ͘͠͞ɻ ൓ԠΛ֬ೝͰ͖ͨΒʮखΛԼΖ͍ͯͩ͘͠͞ʯͱݴ͏ͷͰ ʮखΛ߱Ζ͢ʯϘλϯΛԡ͍ͯͩ͘͠͞ɻ ߨٛΛεϜʔζʹਐΊΔͨΊɺ͝ڠྗ͓ئ͍͠·͢ɻ ߨٛͷਐΊํʹ͍ͭͯ 13

  14. ٳܜʹ͍ͭͯ ͜ͷը૾͕ࡌ͍ͬͯΔεϥΠυ͕͋Δ࣌͸10෼ٳܜͰ͢ɻ ͜ͷߨٛͰ͸͜·ΊʹٳܜΛೖΕͯਐΊ͍͖ͯ·͢ɻ ߨٛͷਐΊํʹ͍ͭͯ 14

  15. खΛಈ͔͢࡞ۀͰͷεϥΠυʹ͍ͭͯ ʮ։ൃ؀ڥߏஙʯͱʮLaravelΛ࢖ͬͯAPIΛ࡞੒͢ΔʯͰ͸खΛಈ͔ͯ͠΋ Β͍·͢ɻԼهͷλά͕ग़͍ͯͳ͍εϥΠυ͸࠲ֶͳͷͰɺεϥΠυΛݟͳ͕ ΒߨٛΛฉ͍͍ͯͩ͘͞ɻ ߨٛͷਐΊํʹ͍ͭͯ ࡞ۀ ʮ࡞ۀʯ͕͍͍ͭͯΔεϥΠυ͸࣮ࡍʹखΛಈ͔͠ͳ ͕Βߦ͏ύʔτʹͳΓ·͢ɻ࣮ࡍʹίʔσΟϯάΛ͠ ͨΓɺઃఆͨ͠Γ͢Δ࡞ۀͰग़͖ͯ·͢ɻ ֬ೝ

    ʮ֬ೝʯ͕͍͍ͭͯΔεϥΠυ͸ಈ࡞Λ֬ೝͨ͠Γɺ ฦ͖ͬͯͨ݁ՌΛ֬ೝ͠·͢ɻ 15
  16. DEMOεϥΠυͱ࡞ۀεϥΠυʹ͍ͭͯ DEMOεϥΠυͷද͕ࣔग़͍ͯΔ࣌͸ɺߨࢣ͕ը໘ݟͤͳ͕Β࣮ࡍʹDEMOΛߦ ͍·͢ɻ ߨٛͷਐΊํʹ͍ͭͯ 16

  17. ࡞ۀεϥΠυ͕ग़͍ͯΔ࣌͸ɺօ͞ΜʹखΛಈ͔ͯ͠࡞ۀΛͯ͠΋Β͍·͢ɻ HH:MM·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ ΍Δ͜ͱ ɾXXXΛ͢Δ ɾOOOΛ࣮ߦ ֬ೝ ɾXX͕දࣔ͞Εͨ DEMOεϥΠυͱ࡞ۀεϥΠυʹ͍ͭͯ ߨٛͷਐΊํʹ͍ͭͯ 17

  18. ࠲ֶ

  19. Webʹ͍ͭͯ Webʹ͍͓ͭͯ͞Β͍Λ͠·͠ΐ͏ 19

  20. Webʹ͍ͭͯ Web ͷؔ࿈ٕज़͸ͱͯ΋ѻ͍΍͘͢ɺ༷ʑͳͱ͜ΖͰར༻͞Ε͍ͯ·͢ɻ - Chrome ΍ Edge ͳͲͷϒϥ΢βͰاۀ΍αʔϏεͷWebϖʔδΛݟΔ - ΦʔιυοΫεͳ࢖ΘΕํ

    - PCɾεϚϗɾςϨϏͱ͍༷ͬͨʑͳσόΠε͔ΒݟΔ͜ͱ͕Ͱ͖Δ - εϚϗͷήʔϜΞϓϦͰ௨৴Λߦ͍ͳ͕ΒڠྗϓϨΠΛ͢Δ - ϒϥ΢βҎ֎ͷ༷ʑͳΞϓϦ΋σʔλͷ΍ΓऔΓʹར༻͍ͯ͠Δ Webʹ͍ͭͯ 20
  21. ΫϥΠΞϯτͱαʔόʔ αʔϏεΛఏڙ͢ΔଆΛαʔόʔɺαʔϏεΛड͚ΔଆΛΫϥΠΞϯτͱ ݺͼ·͢ʢҰൠతͳݴ༿ʹͳΓͭͭ͋Γ·͢Ͷʣɻ ΫϥΠΞϯτͷ୅දྫ͕ϒϥ΢β - Google Chrome - Microsoft EdgeɺInternet

    Explorer - Apple Safari - Mozilla Firefox αʔόʔͱͯ͠ར༻͞Ε͍ͯΔ୅දతͳ΋ͷ - Apache HTTP Server - Nginx (ΤϯδϯΤοΫε) - Microsoft IIS (Internet Information Services) - LiteSpeed Web Server Webʹ͍ͭͯ 21
  22. URL ͱ HTTP Web Ͱ͸࣍ͷ2͕ͭͱͯ΋ॏཁͳཁૉͱͳΓ·͢ɻ URL (Uniform Resource Locator) ʮཉ͍͠৘ใ͕Ͳ͜ʹ͋Δͷ͔ʯͱ͍͏৔ॴΛ໌֬ʹࣔ͢

    HTTP (HyperText Transfer Protocol) URL Ͱࣔͨ͠৔ॴʹରͯ͠ʮ৘ใΛͲ͏͍͔ͨ͠ʯΛ௨৴Ͱࢦࣔ͢Δ ্هͷ2ͭΛ͜ΕҎ߱΋͏গ͚ͩ͠ਂ۷Γ͠·͢ɻ Webʹ͍ͭͯ 22
  23. URLͱ͸ URLΛ࢖͏͜ͱͰʮͲ͜ʹͳʹ͕͋Δ͔ʯΛ؆୯ʹࣔ͢͜ͱ͕Ͱ͖·͢ɻ URL͕ͳ͔ͬͨΒ… - ͋ͷاۀαʔόʔͷ˓˓ͱ͍͏ΧςΰϦԼͷ˚˚ͱ͍͏αϒΧςΰϦΛΈͯʂ - ͱͯ΋େม URL͕͋ͬͨΒ… - https://example.com/◦◦/△△/

    ΛΈͯʂ - ৔ॴΛࢦࣔ͢͠ͷʹγϯϓϧͳϧʔϧΛఏڙͰ͖ͨͷͰɺར༻͢Δͷ͕ͱͯ΋؆୯ʹͳͬͨ Webʹ͍ͭͯ 23
  24. ϓϩτίϧͱ͸ ϓϩτίϧͱ͸௨৴͢Δࡍͷखॱ΍ن֨ΛఆΊͨن໿ͷ͜ͱͰ͢ɻ ϓϩτίϧʹै͏͜ͱͰɺαʔόʔͱΫϥΠΞϯτ͕ωοτϫʔΫΛ ௨ͯ͡΍ΓऔΓͰ͖·͢ɻ - ΫϥΠΞϯτ͕αʔόʔʹܾΊΒΕ໋ͨྩ (1ͭ΋͘͠͸ෳ਺) Λૹ৴͢Δͱ݁Ռ ͕ฦΔ -

    Web Ͱ͸ URL Ͱࣔ͞Εͨ৔ॴʹରͯ͠ HTTP ͱ͍͏ϓϩτίϧͰ΍Γ औΓΛߦ͏ Webʹ͍ͭͯ 24
  25. HTTP ͷྑ͞ HTTP ͸ͦΕ·Ͱ͋ͬͨϓϩτίϧΑΓ͔ͳΓ୯७ͳ΋ͷͱͳ͍ͬͯ·͢ɻ Ҏલͷϓϩτίϧ - SMTP ΍ POP3/IMAP4 (ϝʔϧͰ࢖༻)

    - FTP (ϑΝΠϧసૹͰ࢖༻) ౳ - ෳ਺ͷ໋ྩΛ૊Έ߹Θͤͯ໨తͷಈ࡞Λߦ͏ HTTP - (جຊతʹ) 1ͭͷ໋ྩͰ໨తΛՌͨͤΔ - ϓϩτίϧ͕୯७ͳͨΊɺαʔόʔ΍ΫϥΠΞϯτΛ࣮૷͠΍͍͢ HTTP Λར༻ͨ͠ϓϩμΫτ΍ࣄྫ͕രൃతʹ૿͑·ͨ͠ɻ Webʹ͍ͭͯ 25
  26. Webϖʔδ͕දࣔ͞ΕΔ·Ͱ Webϖʔδ͕දࣔ͞ΕΔ·Ͱʹͳʹ͕ى͖͍ͯΔ͔Λ આ໌͍͖ͯ͠·͢ɻ 26

  27. ϦΫΤετͱϨεϙϯε ΫϥΠΞϯτͱαʔόʔͱͷ΍ΓऔΓʹରͯ͠ͷ༻ޠΛઆ໌͠·͢ɻ ϦΫΤετ ΫϥΠΞϯτ͔Βαʔόʔʹ઀ଓ͠ɺαʔϏεΛఏڙͯ͠΋Β͏ͨΊͷॲཧΛґཔ͢Δ͜ͱΛ ʮϦΫΤετΛ౤͛Δʯͱ͍͏ Ϩεϙϯε ΫϥΠΞϯτ͔ΒͷϦΫΤετΛड͚ͯɺαʔόʔͰॲཧΛߦͬͨ݁ՌΛΫϥΠΞϯτʹ౉͢͜ͱΛ ʮϨεϙϯεΛฦ͢ʯͱ͍͏ Webϖʔδ͕දࣔ͞ΕΔ·Ͱ 27

  28. HTTP ͷ΍ΓऔΓ ྫ͑͹ɺYahoo! JAPAN ͷϖʔδΛදࣔ͢Δ·ͰΛߟ͑ͯΈ·͠ΐ͏ɻ 1. ϒϥ΢β͔Β Yahoo! JAPAN ͷWebαʔόʔʹτοϓϖʔδͷ৘ใΛ΋Β͏ͨΊʹ

    τοϓϖʔδͷURL ʹରͯ͠ϦΫΤετΛ౤͛Δ 1. Webαʔόʔ͸τοϓϖʔδͷσʔλΛ४උͯ͠ɺϒϥ΢βʹϨεϙϯεͱͯ͠ HTML ϑΝΠϧΛฦ͢ 2. ϒϥ΢β͕ HTML ϑΝΠϧΛղੳ͢ΔͱɺCSS ΍ JavaScriptɺը૾ͱ͍ͬͨϑΝΠϧΛ ௥ՃͰऔಘ͢Δඞཁ͕͋Δ͜ͱ͕൑໌͢Δ 1. ϒϥ΢β͔ΒWebαʔόʔʹ ඞཁͳ΋ͷΛ΋Β͏ͨΊʹ౤͛Δ 2. αʔόʔ͔Βϒϥ΢βʹϦΫΤετ͞Εͨ΋ͷΛฦ͢ ...ҎԼ͜Εͷ܁Γฦ͠ Webϖʔδ͕දࣔ͞ΕΔ·Ͱ 28
  29. ϒϥ΢β͔Β Yahoo! JAPAN ͷWebαʔόʔʹτοϓϖʔδͷ৘ใΛ ΋Β͏ͨΊʹτοϓϖʔδͷURL ʹରͯ͠ϦΫΤετΛ౤͛·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ1ʣ ϦΫΤετ

    29
  30. ϒϥ΢β͔Β Yahoo! JAPAN ͷWebαʔόʔʹτοϓϖʔδͷ৘ใΛ ΋Β͏ͨΊʹτοϓϖʔδͷURL ʹରͯ͠ϦΫΤετΛ౤͛·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ1ʣ ϦΫΤετ

    GET https://www.yahoo.co.jp/ HTTP/1.1 Host: www.yahoo.co.jp Connection: keep-alive accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/ webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 accept-encoding: gzip, deflate, br accept-language: ja,en-US;q=0.9,en;q=0.8 cookie: ... sec-fetch-dest: document sec-fetch-mode: navigate sec-fetch-site: none sec-fetch-user: ?1 upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/ 537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 30
  31. ϒϥ΢β͔Β Yahoo! JAPAN ͷWebαʔόʔʹτοϓϖʔδͷ৘ใΛ ΋Β͏ͨΊʹτοϓϖʔδͷURL ʹରͯ͠ϦΫΤετΛ౤͛·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ1ʣ ϦΫΤετ

    GET https://www.yahoo.co.jp/ HTTP/1.1 Host: www.yahoo.co.jp Connection: keep-alive accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/ webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 accept-encoding: gzip, deflate, br accept-language: ja,en-US;q=0.9,en;q=0.8 cookie: ... sec-fetch-dest: document sec-fetch-mode: navigate sec-fetch-site: none sec-fetch-user: ?1 upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/ 537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 GET https://www.yahoo.co.jp/ HTTP/1.1 31
  32. ϒϥ΢β͔Β Yahoo! JAPAN ͷWebαʔόʔʹτοϓϖʔδͷ৘ใΛ ΋Β͏ͨΊʹτοϓϖʔδͷURL ʹରͯ͠ϦΫΤετΛ౤͛·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ1ʣ ϦΫΤετ

    GET https://www.yahoo.co.jp/ HTTP/1.1 Host: www.yahoo.co.jp Connection: keep-alive accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/ webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 accept-encoding: gzip, deflate, br accept-language: ja,en-US;q=0.9,en;q=0.8 cookie: ... sec-fetch-dest: document sec-fetch-mode: navigate sec-fetch-site: none sec-fetch-user: ?1 upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/ 537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 GET https://www.yahoo.co.jp/ HTTP/1.1 ϦΫΤετ ϝιου URL HTTPͷ όʔδϣϯ 32
  33. ϦΫΤετϝιου ϦΫΤετϝιου͸ɺURLʹରͯ͠ͲͷΑ͏ͳॲཧΛ͍ͨ͠ͷ͔Λ ࣔͨ͠΋ͷͰ͢ɻ GET - ৘ใΛऔಘ - ෭࡞༻͸ͳ͍Α͏ʹ POST -

    ৘ใΛมߋ PUT - ৘ใΛஔ׵ PATCH - ৘ใΛҰ෦ஔ׵ DELETE - ৘ใΛ࡟আ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ1ʣ 33
  34. Webαʔόʔ͸τοϓϖʔδͷσʔλΛ४උͯ͠ɺϒϥ΢βʹ Ϩεϙϯεͱͯ͠ html ϑΝΠϧΛฦ͠·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ2ʣ Ϩεϙϯε 34

  35. Webαʔόʔ͸τοϓϖʔδͷσʔλΛ४උͯ͠ɺϒϥ΢βʹ Ϩεϙϯεͱͯ͠ html ϑΝΠϧΛฦ͠·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ2ʣ Ϩεϙϯε HTTP/1.1 200

    OK Cache-Control: private, no-cache, no-store, must-revalidate Content-Type: text/html; charset=UTF-8 Date: Mon, 20 Apr 2020 06:59:26 GMT Expires: -1 Pragma: no-cache Set-Cookie: B=18kikclf9qi2e&b=3&s=2m; expires=Thu, 21-Apr-2022 06:59:26 GMT; pat h=/; domain=.yahoo.co.jp Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Vcap-Request-Id: 075691ed-bab6-4077-58f0-34523d132299 X-Xss-Protection: 1; mode=block Age: 0 Transfer-Encoding: chunked Connection: keep-alive Via: http/1.1 edge1675.img.bbt.yahoo.co.jp (ApacheTrafficServer [c sSf ]) Server: ATS Set-Cookie: XB=18kikclf9qi2e&b=3&s=2m; expires=Thu, 21-Apr-2022 06:59:26 GMT; pa th=/; domain=.yahoo.co.jp; secure; samesite=none <!DOCTYPE html><html lang="ja">... 35
  36. Webαʔόʔ͸τοϓϖʔδͷσʔλΛ४උͯ͠ɺϒϥ΢βʹ Ϩεϙϯεͱͯ͠ html ϑΝΠϧΛฦ͠·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ2ʣ Ϩεϙϯε HTTP/1.1 200

    OK Cache-Control: private, no-cache, no-store, must-revalidate Content-Type: text/html; charset=UTF-8 Date: Mon, 20 Apr 2020 06:59:26 GMT Expires: -1 Pragma: no-cache Set-Cookie: B=18kikclf9qi2e&b=3&s=2m; expires=Thu, 21-Apr-2022 06:59:26 GMT; pat h=/; domain=.yahoo.co.jp Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Vcap-Request-Id: 075691ed-bab6-4077-58f0-34523d132299 X-Xss-Protection: 1; mode=block Age: 0 Transfer-Encoding: chunked Connection: keep-alive Via: http/1.1 edge1675.img.bbt.yahoo.co.jp (ApacheTrafficServer [c sSf ]) Server: ATS Set-Cookie: XB=18kikclf9qi2e&b=3&s=2m; expires=Thu, 21-Apr-2022 06:59:26 GMT; pa th=/; domain=.yahoo.co.jp; secure; samesite=none <!DOCTYPE html><html lang="ja">... HTTP/1.1 200 OK 36
  37. Webαʔόʔ͸τοϓϖʔδͷσʔλΛ४උͯ͠ɺϒϥ΢βʹ Ϩεϙϯεͱͯ͠ html ϑΝΠϧΛฦ͠·͢ɻ Yahoo! JAPAN ͷϖʔδ͕ݟ͑Δ·Ͱʢͦͷ2ʣ Ϩεϙϯε HTTP/1.1 200

    OK Cache-Control: private, no-cache, no-store, must-revalidate Content-Type: text/html; charset=UTF-8 Date: Mon, 20 Apr 2020 06:59:26 GMT Expires: -1 Pragma: no-cache Set-Cookie: B=18kikclf9qi2e&b=3&s=2m; expires=Thu, 21-Apr-2022 06:59:26 GMT; pat h=/; domain=.yahoo.co.jp Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Vcap-Request-Id: 075691ed-bab6-4077-58f0-34523d132299 X-Xss-Protection: 1; mode=block Age: 0 Transfer-Encoding: chunked Connection: keep-alive Via: http/1.1 edge1675.img.bbt.yahoo.co.jp (ApacheTrafficServer [c sSf ]) Server: ATS Set-Cookie: XB=18kikclf9qi2e&b=3&s=2m; expires=Thu, 21-Apr-2022 06:59:26 GMT; pa th=/; domain=.yahoo.co.jp; secure; samesite=none <!DOCTYPE html><html lang="ja">... HTTP/1.1 200 OK HTTPͷ όʔδϣϯ εςʔλε ίʔυ εςʔλε ςΩετ 37
  38. εςʔλείʔυ εςʔλείʔυ͸ɺαʔόʔͷॲཧ݁ՌΛࣔͨ͠΋ͷͰ͢ɻ 3ܻͷ਺஋ͰͲͷΑ͏ͳঢ়ଶʹͳ͔ͬͨΛද͠·͢ɻ - 200൪୆͸ॲཧ͕੒ޭͨ͜͠ͱΛද͢ - 200 OK - 201

    Created - 300൪୆͸௥Ճͷॲཧ͕ඞཁͰ͋Δ͜ͱΛද͢ - 301 Moved Permanently - 302 Found - 307 Temporary Redirect - 308 Permanent Redirect εςʔλείʔυ 38
  39. εςʔλείʔυ - 400൪୆͸ϦΫΤετʹ໰୊͕͋ͬͨ͜ͱΛද͢ - 400 Bad Request - 401 Unauthorized

    - ೝূ͕ඞཁ - 403 Forbidden - 404 Not Found - 500൪୆͸αʔόʔଆʹ໰୊͕͋ͬͨ͜ͱΛද͢ - 500 Internal Server Error - 503 Service Unavailable εςʔλείʔυ 39
  40. ิ଍ 40

  41. ϦΫΤετ΋Ϩεϙϯε΋୯ͳΔςΩετͳͷͰɺͦͷ··Ͱ͸؆୯ʹ த਎ΛݟΒΕͯ͠·͍·͢ɻ TLS (Transport Layer Security) - ௨৴૬खͷೝূɺ௨৴ͷ҉߸ԽΛߦ͏ϓϩτίϧ - Ҏલ͸

    SSL (Secure Sockets Layer) ͱݺ͹Ε͍ͯͨ - SSL ͷݹ͍όʔδϣϯͰ࢖ΘΕ͍ͯͨ҉߸ํ͕ࣜഁΒΕͯ͠·ͬͨͨΊɺSSL ͷ্Ґن໿ͱͯ͠ TLS ͕࡞ΒΕͨ - SSL ͱ TLS Λ·ͱΊͯ SSL ͱݺ͹ΕΔ͜ͱ΋ଟ͍ HTTPS - SSL/TLS ϓϩτίϧͰ઀ଓͷ্Ͱ HTTP ௨৴Λߦ͏͜ͱ - SSL/TLS ͕࢖ΘΕ͍ͯͳ͍ঢ়ଶͩͱURL͸ http://ʙ - SSL/TLS ͕࢖ΘΕ͍ͯΔঢ়ଶͰ͸ https://ʙ ʹͳΔ ҆શͳ௨৴Λ͢ΔͨΊʹ 41
  42. ಛఆͷ୭͔͚ͩར༻͍ͤͨ͞ ఏڙ͢ΔίϯςϯπʹΑͬͯ͸ɺձһ͚͕ͩ࢖͑Δͱ͔ɺಛఆͷਓ͚͕ͩ࢖͑Δ ͱ੍͍ͬͨݶΛ͍ͨ͜͠ͱ͕Α͋͘Γ·͢ɻ ೝূ (Authentication) - ୭Ͱ͋Δ͔Λ֬ೝͯ͠ɺڐՄ͞ΕͨਓҎ֎͸ڐ͞ͳ͍ - ྫɿiPhone ͷ

    Face ID Λ༻͍ͨೝূͳͲ ೝՄ (Authorization) - ୭Ͱ͋Δ͔ʹԠͯ͡ɺͲͷΑ͏ͳݖར͕͋Δ͔Λίϯτϩʔϧ͢Δ - ྫɿөըؗͰόΠΦϨϯεͳөըΛΈΔͳͲ ೔ຊޠͰ΋ࣅͨΑ͏ͳ༻ޠͩ͠ɺӳޠͰ΋྆ํͱ΋ུ͢ͱ Auth ͱͳΓɺࠞಉ͞ΕΔࣄ͕ଟ͍ͷͰ஫ҙ͠·͠ΐ͏ɻ 42
  43. υΩϡϝϯτϧʔτ - URL (https://<server_name>/) ͷτοϓ෦෼ͱରԠ͢Δαʔόʔ্ͷσΟϨΫτϦͷ͜ͱ - ≒υΩϡϝϯτϧʔτʹϑΝΠϧΛஔ͘ͱWebʹެ։͞ΕΔ - Linux ΛWebαʔόʔʹηοτΞοϓ͢Δͱ

    /var/www/html ͕υΩϡϝϯτϧʔτʹͳΔ - ઃఆϑΝΠϧͰมߋՄೳ - ϨϯλϧαʔόʔͰ͸1ͭͷαʔόʔΛෳ਺ͷ͓٬༷͕ར༻͢ΔͷͰɺ͓٬༷ͷυϝΠϯຖʹ υΩϡϝϯτϧʔτΛઃఆ͍ͯ͠Δ υΩϡϝϯτϧʔτʹϑΝΠϧΛແ଄࡞ʹஔ͘ͱɺWebϒϥ΢β͔Β؆୯ʹΞΫηε͞Εͯ͠·͏ɻ ͜ͷͨΊɺݟΒΕͯ͸͍͚ͳ͍σʔλ͸ /var/www/data ͳͲͷυΩϡϝϯτϧʔτ֎ͷσΟϨΫτϦʹ ஔ͘Α͏ʹ͠·͠ΐ͏ʢ৘ใ࿙͍͑ͷҰ෦͸υΩϡϝϯτϧʔτʹޡͬͯϑΝΠϧΛஔ͍ͨ͜ͱͰൃੜ͍ͯ͠·͢ʣɻ ิ଍ 43
  44. 16࣌50෼·Ͱٳܜ 44

  45. WebΞϓϦέʔγϣϯʹ ͍ͭͯ WebΞϓϦέʔγϣϯʹֶ͍ͭͯΜͰ͍͖·͠ΐ͏ 45

  46. Web ΞϓϦέʔγϣϯΛ෼ྨͯ͠ΈΔ WebϖʔδΛදࣔ͢ΔͨΊͷΞϓϦέʔγϣϯ - αʔόʔ͔Β͸ HTML, JavaScript, CSS, ը૾ͳͲΛฦ͢ -

    ݹ͔͘Βఏڙ͞Ε͖ͯͨ΋ͷ εϚϗ౳͔Βར༻͞ΕΔΞϓϦέʔγϣϯ - εϚϗΞϓϦ౳͔ΒΞΫηε͞Εɺσʔλͷऔಘ΍ߋ৽Λߦ͏ - ʮσʔλΛͲ͏΍ΓऔΓΛ͢Δ͔ʯͱ͍͏ܾ·ΓΛΞϓϦέʔγϣϯຖʹܾΊͯɺ ΫϥΠΞϯτͱαʔόʔͰ΍ΓऔΓΛߦ͏ - ͜ͷܾ·Γͷ͜ͱΛ API (Application Programming Interface) ͱ͍͏ ࠓճͷߨٛͰ͸͜ͷ API ͷ࣮૷ํ๏Λֶͼ·͢ɻ WebΞϓϦέʔγϣϯʹ͍ͭͯ 46
  47. RESTful API API ͷઃܭํ๏ʹ͸͍͔ͭ͘ͷྲّྀ͕͋Γ·͢ʢRPC ΍ SOAPͳͲʣɻ Web API ͸ SOAP

    (Simple Object Access Protocol) ͳͲͰఏڙ͞Ε͍ͯͨ - γεςϜຖʹෳࡶͳ࢓༷ॻ (XMLͷߏ଄ͳͲ) ͷ΍ΓऔΓ͕ඞཁ - ࡞੒͢ΔγεςϜ͕৭ʑͰ͖Δ͕ෳࡶʹͳΓ͕ͪ RESTful API - URL ͕ࣔ͢΋ͷʹରͯ͠ HTTP ͷϝιουΛ࢖ͬͯ୯७ʹΞΫηε͢Δ - ࢓༷͕γϯϓϧʹͳΔͷͰɺෳ਺ͷγεςϜ࿈ܞ͕ൺֱత༰қʹͳΔ ࡢࠓ͸ RESTful API Ͱఏڙ͢Δ΋ͷ͕ଟ͍Ͱ͢ɻ WebΞϓϦέʔγϣϯʹ͍ͭͯ 47
  48. REST ͱ͍͏ߟ͑ํ Web ͰγεςϜΛߏங͢Δʹ͋ͨͬͯɺͲͷΑ͏ʹ͢Δͱޮ཰͕͍͍ͷ͔ͱ ͍͏ߟ͑ํ͕ HTTP ͷن໿Λࡦఆͨ͠ϝϯόʔͷҰਓͰ͋Δ Roy Fielding ʹΑͬͯఏএ͞Ε·ͨ͠ɻ

    REST (REpresentational State Transfer) - ֦ுੑͷ͋Δ Web γεςϜΛߏங͢ΔͨΊͷ ΞʔΩςΫνϟελΠϧ(ઃܭͷྲّྀ΍༷ࣜɺ࡞๏) - ΫϥΠΞϯτͱαʔόʔͷؒΛURLͱ౷ҰΠϯλϑΣʔε (ϦΫΤετϝιου) Λ࢖ͬͯ εςʔτϨεʹ΍ΓऔΓ͢Δ͜ͱʹΑΓ֦ுੑΛߴΊΔΑ͏ʹͰ͖Δͱͨ͠ߟ͑ - Web ͓Αͼ HTTP ͦͷ΋ͷͷݪଇͱݴ͑Δ WebΞϓϦέʔγϣϯʹ͍ͭͯ 48
  49. CRUD ͱ͍͏ߟ͑ํ CRUD ͱ͸ɺσʔλૢ࡞Ͱ࢖͏4ͭͷجຊػೳͷͦΕͧΕͷ಄จࣈΛͱͬͨ΋ͷͰ ͢ɻ͜ΕΛ RESTful API ʹϚοϐϯά͢ΔͱҎԼͷ௨ΓͰ͢ɻ Create -

    σʔλΛੜ੒͢Δ - POST <URL> Read - σʔλΛಡΈऔΔ - GET <URL> Update - σʔλΛߋ৽͢Δ - PUT <URL> or PATCH <URL> Delete - σʔλΛ࡟আ͢Δ - DELETE <URL> WebΞϓϦέʔγϣϯʹ͍ͭͯ 49
  50. ฦ٫͞ΕΔσʔλͷܗࣜ ௨ৗͷWebΞϓϦέʔγϣϯͰ͸ HTML ΍ JavaScriptɾCSS ͳͲ͕ฦ٫ ͞Ε·͕͢ɺAPI Ͱ͸ͦΕͱ͸ҧͬͨܗࣜͰσʔλΛฦ٫͠·͢ɻ ύʔε -

    ϓϩάϥϜͰσʔλ (จࣈྻ) ղੳ͢Δ͜ͱ - API Ͱѻ͏σʔλ͸ϓϩάϥϜͰॲཧ͠΍͍͢ܗࣜΛ બͿʢHTML ΍୯ͳΔෳ਺ߦςΩετ͸ύʔεͮ͠Β͍ʣ ύʔε͠΍͍͢σʔλܗࣜ - XML (Extensible Markup Language) - σʔλʹରͯ͠ݫີʹλάΛ෇༩ͨ͠σʔλܗࣜ - JSON (JavaScript Object Notation) - JavaScript Ͱͦͷ··ར༻ՄೳͰɺͦͷଞݴޠͰ΋ѻ͍΍͍͢ - ࠓճͷߨٛͰ͸ JSON ΛऔΓѻ͏ WebΞϓϦέʔγϣϯʹ͍ͭͯ 50
  51. JSON αϯϓϧίʔυͰൺֱ WebΞϓϦέʔγϣϯʹ͍ͭͯ XML HTML <!doctype html> <html> <head> <meta

    charset="utf-8"> </head> <body> <form> <input
 type="text"
 name="key"
 value="value"> </form> </body> </html> { "key": "value" } <?xml version="1.0" encoding="utf-8" ?> <key>value</key> 51
  52. WebΞϓϦέʔγϣϯΛ ࡞੒͢Δʹ͋ͨͬͯ WebΞϓϦέʔγϣϯΛ࡞੒͢Δʹ͋ͨͬͯඞཁͳ஌ࣝΛ આ໌͠·͢ɻ 52

  53. ϑϨʔϜϫʔΫͱ͸ ໌೔ͷϋϯζΦϯͰ࡞੒͢ΔWebΞϓϦέʔγϣϯͰ͸ϑϨʔϜϫʔΫΛ ར༻͠·͢ɻ ϑϨʔϜϫʔΫʢWeb ΞϓϦέʔγϣϯϑϨʔϜϫʔΫʣ - ϞϊΛ࡞੒͢Δࡍɺ0͔Βશͯ࡞Δͷ͸ͱͯ΋େม - ౔୆ͱͯ͠Կׂ͔Ͱ͖͕͋ͬͨϞϊͷ্ʹॲཧΛ௥Ճ͢Δ͜ͱͰɺΞϓϦέʔγϣϯ׬੒·Ͱͷ खؒΛগͳ͘͢Διϑτ΢ΣΞ

    - ϑϨʔϜϫʔΫຖʹϧʔϧ΍࡞๏͕͋Γɺ͜Εʹै͑͹ൺֱత؆୯ʹΞϓϦέʔγϣϯΛ ࡞੒Ͱ͖Δʢٯʹݴ͑͹ϑϨʔϜϫʔΫຖʹบ͕͋Γɺ߹Θͤͯ࡞Δඞཁ͕͋Δʣ ϥΠϒϥϦͱͷҧ͍ - ϥΠϒϥϦ͸ࣗ෼͕࡞੒͢ΔϓϩάϥϜ͔Βར༻͢Δ෦඼ - ಛผͳॲཧΛ؆୯ʹ࣮ݱͰ͖ΔΑ͏࡞੒͞Ε͓ͯΓɺ࠶࣮૷͢Δख͕ؒল͚Δ - ϑϨʔϜϫʔΫ͸ࣗ෼͕࡞੒͢ΔϓϩάϥϜ͕ར༻͞ΕΔ෦඼ WebΞϓϦέʔγϣϯΛ࡞੒͢Δʹ͋ͨͬͯ 53
  54. ύλʔϯ ϓϩάϥϜΛઃܭɾ࣮૷ʹ͓͍ͯʮ୭΋͕ࣅ࣮ͨ૷Λ͍ͯ͠Δͳʯͱ ͍͏͜ͱ͕͠͹͠͹ى͜Γ·͢ɻ ύλʔϯ - ࣅͨΞϓϦέʔγϣϯΛ࡞੒͢Δ৔߹ɺޙʑ֦ுɾमਖ਼͠΍͍͢ڞ௨ͷ΍Γํ͕ग़ͯ͘Δ - ख๏΍खॱʹ໊લΛ͚ͭɺΤϯδχΞؒͰڞ௨ͷޠኮͱͯ͠ձ࿩͕Ͱ͖ΔΑ͏ʹͨ͠Ϟϊ Ξϯνύλʔϯ -

    ύλʔϯ͸ྑ͍Ϟϊ͹͔ΓͰ͸ͳ͍ - ʮ͜͏͍͏෩ʹ͢Δͱྑ͘ͳ͍Αʯͱ஫ҙשى͢Δ΋ͷ ϑϨʔϜϫʔΫ͸͜ͷύλʔϯΛଟ͘ར༻͓ͯ͠Γɺͦͷ୅දྫ͕ MVCύλʔϯͰ͢ɻ WebΞϓϦέʔγϣϯΛ࡞੒͢Δʹ͋ͨͬͯ 54
  55. MVCύλʔϯ MVCύλʔϯ (Model-View-Controller ύλʔϯ) - ModelɺViewɺController ͷ3ͭͷύʔπͰΞϓϦέʔγϣϯΛ࡞Δߟ͑ํ Controller - ֎෦͔ΒͷϦΫΤετΛड͚Δ

    - ॲཧΛ Model ʹґཔͯ͠ɺ݁ՌΛड͚औΔ - ॲཧ݁ՌΛ View ʹ౉ͯ͠ɺग़ྗ݁ՌΛड͚औΔ - ग़ྗ݁ՌΛϨεϙϯεͱͯ͠ฦ٫͢Δ Model - ΞϓϦέʔγϣϯͱͯ͠ͷॲཧΛ୲౰͢Δ - DBΞΫηε΍֎෦αʔϏεͱͷ΍ΓऔΓ͸͜͜Ͱߦ͏ View - ॲཧ݁ՌΛͲͷΑ͏ʹΞ΢τϓοτ͢Δ͔Λ୲౰͢Δ - HTMLͷੜ੒΍ɺJSONͷੜ੒ΛߦͬͨΓ͢Δ WebΞϓϦέʔγϣϯΛ࡞੒͢Δʹ͋ͨͬͯ 55
  56. MVCύλʔϯͷಛ௃ MVCύλʔϯ͸ଟ͘ͷϑϨʔϜϫʔΫʹ࠾༻͞Ε͍ͯΔͨΊԠ༻͠΍͍͢ - ࣮૷͢Δࡍʮ MVC ͷͲΕ͕୲౰͢Δ͔ʯͱ͍͏͜ͱͰ੔ཧ͠΍͍͢ - σΟϨΫτϦߏ੒ʢͲ͜ʹԿΛஔ͔͘ʣ͸೰ΈͷλωʹͳΓ΍͍͢ - ΄ͱΜͲͷϑϨʔϜϫʔΫ͸σΟϨΫτϦߏ੒͕ܾ·͓ͬͯΓ

    ͜Εʹै࣮ͬͯ૷͢ΔͷͰ ʢൺֱతʣ ೰·ͳ͍ͰࡁΉ ஫ҙ఺ - MVCͷ୲౰ΛׂΓৼΔࡍɺͲ͏ͯ͠΋ᐆດͳ෦෼͕Ͱ͖ͯ͠·͏ - Controller, Model ͷͲͪΒ͔ͷ୲౰ൣғ͸޿͘ͳΓ͗͢Δ܏޲͕͋Δ WebΞϓϦέʔγϣϯΛ࡞੒͢Δʹ͋ͨͬͯ 56
  57. 17࣌25෼·Ͱٳܜ 57

  58. ։ൃ؀ڥߏங

  59. ConoHaʹαʔόʔΛ௥Ճ͢Δ 59

  60. ConoHaʹαʔόʔΛ௥Ճ͢Δ 60

  61. 17:45·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾݚम༻αʔόʔΛ௥Ճ͢Δ ɾSSH KeyΛμ΢ϯϩʔυ͢Δ ֬ೝ ɾConoHaͷVPSͷҰཡͰΠϯελϯε͕ ɹݟΕΔ͜ͱ

    ࡞ۀλΠϜ ConoHaʹαʔόʔΛ௥Ճ͢Δ ࡞ۀ 61
  62. VSCodeͷ֦ுػೳ Remote-SSHͰ αʔόʔʹΞΫηε͢Δ 62

  63. ͳͥVSCodeΛ࢖༻͢Δͷ͔ VSCodeΛ࢖༻͠ͳ͍৔߹ɺҎԼͷΑ͏ͳ࡞ۀ͕ൃੜ͠·͢ɻ - ίϯιʔϧը໘ʹೖΓίϚϯυϥΠϯͰૢ࡞͢Δඞཁ͕͋Δ - ख͕ؒൃੜ͢Δ - ίϚϯυͷೖྗؒҧ͍Ͱ࡞ۀ͕ࢥ͏Α͏ʹਐ·ͳ͍ - viͳͲͷ஌͕ࣝඞཁ

    - मਖ਼ՕॴΛ୳͢ͷ͕େม Remote-SSHͰαʔόʔʹΞΫηε͢Δ 63
  64. ͳͥVSCodeΛ࢖༻͢Δͷ͔ VSCodeΛ࢖༻ͨ͠৔߹ɺҎԼͷΑ͏ͳϝϦοτ͕͋Γ·͢ɻ - GUIͰָʹૢ࡞Ͱ͖Δ - ࣗಈͰΠϯσϯτ΍ิ׬Λͯ͘͠ΕΔͷͰɺϑΝΠϧͷத਎Λฤू͢Δͷָ͕ - ֦ுػೳΛೖΕͯࣗ෼޷ΈʹΧελϚΠζͰ͖Δ Remote-SSHͰαʔόʔʹΞΫηε͢Δ 64

  65. Πϝʔδਤ - VSCodeΛ࢖༻͠ͳ͍৔߹ Remote-SSHͰαʔόʔʹΞΫηε͢Δ खݩͷPC؀ڥ ConoHa VPS ্ͷ؀ڥ SSH ઀ଓ

    65
  66. Πϝʔδਤ - VSCodeΛ࢖༻͠ͳ͍৔߹ Remote-SSHͰαʔόʔʹΞΫηε͢Δ खݩͷPC؀ڥ ConoHa VPS ্ͷ؀ڥ SSH ઀ଓ

    viͰฤू େมʂ 66
  67. Πϝʔδਤ - VSCodeΛ࢖༻ͨ͠৔߹ Remote-SSHͰαʔόʔʹΞΫηε͢Δ खݩͷPC؀ڥ ConoHa VPS ্ͷ؀ڥ SSH ઀ଓ

    Remote-SSH 67
  68. Πϝʔδਤ - VSCodeΛ࢖༻ͨ͠৔߹ Remote-SSHͰαʔόʔʹΞΫηε͢Δ खݩͷPC؀ڥ ConoHa VPS ্ͷ؀ڥ SSH ઀ଓ

    Remote-SSH VSCodeͰฤू ؆୯ʂ 68
  69. ͜Ε͔Βߦ͏۩ମతͳखॱ 1. VSCodeʹ֦ுػೳ Remote-SSH ΛΠϯετʔϧ͢Δ 2. VSCode Remote-SSH ͷ઀ଓઃఆ a.

    SSH Key ͷݖݶมߋ͢Δ b. VSCode Remote-SSH ʹ઀ଓઃఆΛ௥Ճ͢Δ Remote-SSHͰαʔόʔʹΞΫηε͢Δ 69
  70. VSCodeʹRemote-SSHΛΠϯετʔϧ͢Δ VSCodeͷ֦ுػೳͷݕࡧը໘(Crt+Shift+X)͔ΒRemote-SSHΛݕࡧͯ͠Πϯετʔϧ͠·͢ɻ Remote-SSHͰαʔόʔʹΞΫηε͢Δ ࡞ۀ 70

  71. VSCodeʹRemote-SSHΛΠϯετʔϧ͢Δ Πϯετʔϧ͕׬ྃ͢ΔͱVSCodeͷࠨͷΞΠίϯҰཡʹRemote-SSH༻ͷΞΠίϯ͕දࣔ͞Ε·͢ɻ Remote-SSHͰαʔόʔʹΞΫηε͢Δ ࡞ۀ 71

  72. Remote-SSHͰConoHa VPSʹΞΫηε͢Δ mac൛ 72

  73. Remote-SSHͰConoHa VPSʹΞΫηε͢Δ windows൛ 73

  74. αʔόʔͷઃఆ͕ਖ਼͘͠Ͱ͖͍ͯΔ͔֬ೝ͠Α͏ Remote-SSHͰConoHa VPSʹΞΫηε͢Δ ࡞ۀ root@αʔόʔ໊ ͱදࣔ͞Ε͍ͯΔλʔϛφϧͰ࡞ۀ͠·͢ cd /var/www/html pwd #

    ͜ͷΑ͏ʹදࣔ͞Ε͍ͯΔ͜ͱΛ֬ೝ͍ͯͩ͘͠͞ /var/www/html ΋͠Τϥʔ͕ग़ͨΓɺ্هͷΑ͏ͳ݁Ռ͕දࣔ͞Εͳ͔ͬͨΒɺ VPSͷॳظઃఆ͕ؒҧ͍ͬͯΔՄೳੑ͕͋Γ·͢ɻ ݱࡏͷΠϯελϯεΛ࡟আͯ͠ɺ࠶౓VPSͷઃఆ͔Β΍Γ௚͠·͠ΐ͏ɻ खΛڍ͛ͯڭ͍͍͑ͯͨͩͨΒϑΥϩʔ͠·͢ʂ
  75. 18:40 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾVSCodeʹRemote-SSHΛΠϯετʔϧ ɾRemote-SSHʹConoHaαʔόʔͷઃఆΛొ࿥ ɾConoHaͷαʔόʔʹϩάΠϯ ֬ೝ ɾRemote-SSHͨ͋͠ͱͷλʔϛφϧͰ

    ɹpwdͷ݁Ռ͕ਖ਼͘͠දࣔ͞Ε͍ͯΔ͜ͱ ࡞ۀλΠϜ Remote-SSHͰαʔόʔʹΞΫηε͢Δ ࡞ۀ 75
  76. 1೔໨ऴྃʂ ͓ർΕ༷Ͱͨ͠ʂ

  77. GTB2021 WebΞϓϦέʔγϣϯ ϑϨʔϜϫʔΫೖ໳ / REST API ೖ໳ 2೔໨

  78. εέδϡʔϧͱ୲౰ʹ͍ͭͯ 2೔໨ʢ2021/05/13 10:30ʙ18:45ʣ Laravelʹ͍ͭͯ 1࣌ؒʢ10:30ʙ11:30ʣ kumak1 - Laravelͱ͸ʁ - Laravelͷศརػೳ

    - LaravelͷσΟϨΫτϦߏ੒ - LaravelͰͷॲཧͷྲྀΕΛ֬ೝ͢Δ ߨٛͷਐΊํʹ͍ͭͯ 78
  79. εέδϡʔϧͱ୲౰ʹ͍ͭͯ 2೔໨ʢ2021/05/13 10:30ʙ18:45ʣ LaravelΛ࢖ͬͯAPIΛ࡞੒͢Δ 6࣌ؒʢ11:40ʙ18:45ʣ endu - ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏ - ΞϓϦέʔγϣϯΛϒϥ΢β͔ΒݟͯΈΑ͏

    - APIͷCRUDΛ࣮૷͠Α͏ - ORMͷΑ΋΍·࿩ - ValidationΛ࣮૷͠Α͏ ߨٛͷਐΊํʹ͍ͭͯ 79
  80. Laravelͱ͸ʁ ࠓճͷϑϨʔϜϫʔΫͷߨٛ͸LaravelΛ ࢖ͬͯਐΊ͍͖ͯ·͢ 80

  81. Laravelͷ঺հ PHPͰॻ͔ΕͨϑϨʔϜϫʔΫ - ެࣜυΩϡϝϯτɹ https://laravel.com/ - ೔ຊޠ༁·ͱΊαΠτ https://readouble.com/laravel/ όʔδϣϯʹ͍ͭͯ -

    v1 ͸2011೥6݄ఏڙ։࢝ - ࠷৽όʔδϣϯ͸ 8.Xʢ2021/4 ݱࡏʣ - ൒೥ຖʹϝδϟʔόʔδϣϯΞοϓ - LTSʢLong Term SupportʣͷϦϦʔε͸2೥ຖ - όάϑΟοΫε͸2೥ؒܧଓ - ηΩϡϦςΟϑΟοΫε͸3೥ؒܧଓ ࠓճͷߨٛͰ͸ Laravel 6.Xʢ࠷৽ͷLTSʣΛ࢖༻͠·͢ɻ Laravelͱ͸ʁ 81
  82. ϑϨʔϜϫʔΫͱ͸ ໌೔ͷϋϯζΦϯͰ࡞੒͢ΔWebΞϓϦέʔγϣϯͰ͸ϑϨʔϜϫʔΫΛ ར༻͠·͢ɻ ϑϨʔϜϫʔΫʢWeb ΞϓϦέʔγϣϯϑϨʔϜϫʔΫʣ - ϞϊΛ࡞੒͢Δࡍɺ0 ͔Βશͯ࡞Δͷ͸ͱͯ΋େม - ౔୆ͱͯ͠Կׂ͔Ͱ͖͕͋ͬͨϞϊͷ্ʹॲཧΛ௥Ճ͢Δ͜ͱͰɺΞϓϦέʔγϣϯ׬੒·Ͱͷ

    खؒΛগͳ͘͢Διϑτ΢ΣΞ - ϑϨʔϜϫʔΫຖʹϧʔϧ΍࡞๏͕͋Γɺ͜Εʹै͑͹ൺֱత؆୯ʹΞϓϦέʔγϣϯΛ ࡞੒Ͱ͖Δʢٯʹݴ͑͹ϑϨʔϜϫʔΫຖʹบ͕͋Γɺ߹Θͤͯ࡞Δඞཁ͕͋Δʣ ϥΠϒϥϦͱͷҧ͍ - ϥΠϒϥϦ͸ࣗ෼͕࡞੒͢ΔϓϩάϥϜ ͔Β ར༻͢Δ෦඼ - ಛผͳॲཧΛ؆୯ʹ࣮ݱͰ͖ΔΑ͏࡞੒͞Ε͓ͯΓɺ࠶࣮૷͢Δख͕ؒল͚Δ - ϑϨʔϜϫʔΫ͸ࣗ෼͕࡞੒͢ΔϓϩάϥϜ ͕ ར༻͞ΕΔ෦඼ ෮शʢϑϨʔϜϫʔΫͱ͸ʣ 82
  83. WebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͱ͸ʁ - WebΞϓϦέʔγϣϯͷ։ൃΛαϙʔτ͢ΔͨΊʹઃܭ͞Εͨ΋ͷ - Α͘༻͍ΒΕΔػೳͷͨΊͷϥΠϒϥϦΛఏڙ WebΞϓϦέʔγϣϯʹඞཁͳڞ௨ػೳΛ͋Β͔͡Ί༻ҙ͢Δ͜ͱͰ ׬੒·ͰͷखؒΛগͳ͘͢Διϑτ΢ΣΞͰ͢ɻ ෮शʢWebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͱ͸ʁʣ 83

  84. ϑϨʔϜϫʔΫΛ࢖͏ϝϦοτ ؆୯ʹɺ҆શʹɺ୹͘ॻ͘͜ͱ͕ՄೳʹͳΓ·͢ɻ - ن໿͕༻ҙ͞Ε͍ͯΔ - ن໿ʹఴ͏͜ͱͰ։ൃऀ͝ͱͷίʔσΟϯάͷόϥ෇͖͕཈͑ΒΕΔ - ίʔυ͕ߏ଄Խ͞Ε͍ͯΔ - MVCύλʔϯɺϦϙδτϦύλʔϯͳͲ

    - อकੑ޲্ - ศརͳϞϊ͕༻ҙ͞Ε͍ͯΔ - ίϚϯυϥΠϯΠϯλʔϑΣΠεɺORMͳͲ - ։ൃεϐʔυΞοϓ Laravelͱ͸ʁ 84
  85. ϑϨʔϜϫʔΫΛ࢖͏σϝϦοτ - ֶशίετ͕૿͑Δ - ϑϨʔϜϫʔΫͷ͓࡞๏ͷशಘ͕ඞཁʢݴޠͷ͓࡞๏ͱผʹʣ - ྫɿίϚϯυϥΠϯΠϯλʔϑΣΠεɺORMͷه๏ɺϧʔςΟϯάͳͲ - ϑϨʔϜϫʔΫͷ஌ࣝʹภͬͯ͠·͏ -

    ࡉ͔͍࢓૊ΈΛཧղͤͣʹΞϓϦέʔγϣϯ͕࡞Εͯ͠·͏ͷͰ ϒϥοΫϘοΫεԽ͠΍͍͢ - ΧελϚΠζͮ͠Β͍ʢεΫϥονͱൺ΂ʣ - ΞϓϦέʔγϣϯͷن໛ʹରͯ͠৑௕ʹͳΔ৔߹͕͋Δ Laravelͱ͸ʁ 85
  86. LaravelͷศརػೳͷҰྫ 86

  87. Artisan ʹ͍ͭͯ LaravelͷίϚϯυϥΠϯΠϯλʔϑΣΠε - https://readouble.com/laravel/6.x/ja/artisan.html - Artisan = ৬ਓͱ͍͏ҙຯ ʮphp

    artisan xxxʯͱ͍͏ه๏Ͱ༷ʑͳίϚϯυΛ࣮ߦͰ͖Δ LaravelͷศརػೳͷҰྫ 87
  88. LaravelͷศརػೳͷҰྫ 88 ArtisanίϚϯυ ॲཧ಺༰ php artisan -v Laravelͷόʔδϣϯͷ֬ೝ php artisan

    list ίϚϯυҰཡΛ֬ೝͰ͖Δ php artisan <࣮ߦίϚϯυ> -h ίϚϯυͷ࢖͍ํΛ֬ೝͰ͖Δ php artisan make:controller FooController FooίϯτϩʔϥʔΛ࡞੒͢Δ php artisan make:model Foo FooϞσϧΛ࡞੒͢Δ php artisan make:migration create_tests_table --create=tests create_tests_table=ϑΝΠϧ໊ɺtests=ςʔϒϧ໊ͰϚΠά ϨʔγϣϯϑΝΠϧΛ࡞੒͢Δ php artisan migrate ϚΠάϨʔγϣϯͷ࣮ߦ php artisan migrate:rollback ϚΠάϨʔγϣϯͷϩʔϧόοΫ php artisan route:list ϧʔςΟϯάͷҰཡΛදࣔ php artisan tinker REPLͷىಈʢͪΐͬͱͨ͠σόοάͱ͔ʹศརʣ
  89. ϚΠάϨʔγϣϯʹ͍ͭͯ ҠಈɾҠߦͱ͍͏ҙຯʢwikipediaΑΓҾ༻ʣ - ͜͜Ͱ͸σʔλϕʔεϚΠάϨʔγϣϯͷ͜ͱ - DBʹอଘ͞Ε͍ͯΔσʔλΛอ࣋ͨ͠··ɺςʔϒϧͷ࡞੒΍ΧϥϜͷมߋͳͲΛߦ͏ͨΊͷػೳ ϚΠάϨʔγϣϯͷϝϦοτ - SQLจΛ࡞੒࣮ͯ͠ߦ͠ͳͯ͘΋ɺ؆୯ʹςʔϒϧΛఆٛͰ͖Δ -

    ςʔϒϧͷઃܭΛίʔυͰ؅ཧͰ͖ΔʢϚΠάϨʔγϣϯϑΝΠϧʣ - σʔλϕʔεઃఆ͕όʔδϣϯϑΝΠϧʹΑΓ؅ཧ͞ΕΔ - ෳ਺ਓͰͷ։ൃ࡞ۀ΋΍Γ΍͘͢ͳΔ LaravelͷศརػೳͷҰྫ 89
  90. .envϑΝΠϧʹ͍ͭͯ - ΞϓϦέʔγϣϯͰ࢖͏֤छઃఆؚ͕·ΕΔ - σʔλϕʔεͷ઀ଓઃఆ - ΞϓϦέʔγϣϯݻ༗ͷ؀ڥม਺ʢAPP_KEYͳͲʣ - ։ൃ؀ڥ΍ຊ൪؀ڥͷ੾Γସ͑ -

    Ϧετͨ͠஋͸PHPͷεʔύʔάϩʔόϧม਺΁ϩʔυ͞ΕΔ - ൿಗ৘ใͳͲΛ֎෦͔ΒΞΫηεͰ͖ͳ͍ܗͰอ࣋Ͱ͖Δ .envϑΝΠϧ͸GitHubͳͲʹΞοϓϩʔυͯ͠͸͍͚·ͤΜ LaravelͷศརػೳͷҰྫ 90
  91. .envϑΝΠϧʹ͍ͭͯ .envϑΝΠϧͷهࡌ͞ΕΔ؀ڥม਺ͷྫ LaravelͷศརػೳͷҰྫ 91

  92. LaravelͷσΟϨΫτϦߏ੒ 92

  93. σΟϨΫτϦͷߏ੒ͷҰ෦ MVCͷσΟϨΫτϦ - app/Http/ ModelͷϑΝΠϧؚ͕·ΕΔ - app/Http/Controller/ ControllerͷϑΝΠϧؚ͕·ΕΔ - app/resources/views/

    ViewͷϑΝΠϧؚ͕·ΕΔ ͦͷଞͷσΟϨΫτϦ - app/Console/Commands/ ArtisanͷಠࣗΧελϜίϚϯυ - routes/ɹ ϧʔτఆٛϑΝΠϧ - database/ DBͷϚΠάϨʔγϣϯɾॳظ஋ઃఆϑΝΠϧͳͲ - tests/ɹ ςετ - vendor/ɹ ϥΠϒϥϦͳͲʢcomposer ʹΑΔґଘύοέʔδղܾʣ ※ϑϨʔϜϫʔΫͷछྨʹΑͬͯߏ੒͸ҟͳΓ·͢ɻ ɹ·ͨɺόʔδϣϯʹΑͬͯ΋ҟͳΔ৔߹͕͋Γ·͢ɻ LaravelͷσΟϨΫτϦߏ੒ 93
  94. MVCύλʔϯͷ෮श 94

  95. MVCύλʔϯ MVCύλʔϯ (Model-View-Controller ύλʔϯ) - ModelɺViewɺController ͷ3ͭͷύʔπͰΞϓϦέʔγϣϯΛ࡞Δߟ͑ํ Controller - ֎෦͔ΒͷϦΫΤετΛड͚Δ

    - ॲཧΛ Model ʹґཔͯ͠ɺ݁ՌΛड͚औΔ - ॲཧ݁ՌΛ View ʹ౉ͯ͠ɺग़ྗ݁ՌΛड͚औΔ - ग़ྗ݁ՌΛϨεϙϯεͱͯ͠ฦ٫͢Δ Model - ΞϓϦέʔγϣϯͱͯ͠ͷॲཧΛ୲౰͢Δ - DBΞΫηε΍֎෦αʔϏεͱͷ΍ΓऔΓ͸͜͜Ͱߦ͏ View - ॲཧ݁ՌΛͲͷΑ͏ʹΞ΢τϓοτ͢Δ͔Λ୲౰͢Δ - HTMLͷੜ੒΍ɺJSONͷੜ੒ΛߦͬͨΓ͢Δ MVCύλʔϯͷ෮श 95
  96. MVCύλʔϯͷಛ௃ MVCύλʔϯ ͸ଟ͘ͷϑϨʔϜϫʔΫʹ࠾༻͞Ε͍ͯΔͨΊԠ༻͠΍͍͢ - ࣮૷͢Δࡍʮ MVC ͷͲΕ͕୲౰͢Δ͔ʯͱ͍͏͜ͱͰ੔ཧ͠΍͍͢ - σΟϨΫτϦߏ੒ʢͲ͜ʹԿΛஔ͔͘ʣ͸೰ΈͷλωʹͳΓ΍͍͢ -

    ΄ͱΜͲͷϑϨʔϜϫʔΫ͸σΟϨΫτϦߏ੒͕ܾ·͓ͬͯΓ ͜Εʹै࣮ͬͯ૷͢ΔͷͰʢൺֱతʣ೰·ͳ͍ͰࡁΉ ஫ҙ఺ - MVCͷ୲౰ΛׂΓৼΔࡍɺͲ͏ͯ͠΋ᐆດͳ෦෼͕Ͱ͖ͯ͠·͏ - Controller, Model ͷͲͪΒ͔ͷ୲౰ൣғ͸޿͘ͳΓ͗͢Δ܏޲͕͋Δ →͔࣍ΒɺLaravelͰMVCΛݟ͍͖ͯ·͢ 96 MVCύλʔϯͷ෮श
  97. ॲཧͷྲྀΕΛMVCʹԊͬͯ ݟͯΈΑ͏ 97

  98. ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 98 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ ෰ͷҰཡΛ ݟ͍ͨ

  99. ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 99 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ ෰ͷҰཡΛ ݟ͍ͨ Response GET /clothes ෰ͷҰཡϖʔδΛϨεϙϯεͰฦ͢ Request

  100. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 100 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller
  101. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 101 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ Controller /clothesΛݩʹControllerʹ

    ભҠ͠·͢ ᶄ ᶅ ᶆ ᶇ ᶈ ᶉ
  102. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 102 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶄ ᶅ ᶆ

    ᶇ ᶈ ᶉ Controller ControllerଆͰʮ෰ͷҰཡΛ औಘ͢ΔʯॲཧΛݺͼग़͠·͢ ᶃ
  103. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 103 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller DB͔ΒσʔλΛऔಘ͍ͨ͠ͷͰ Ϟσϧʹॲཧ͕ҠΓ·͢
  104. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 104 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller Modelܦ༝ͰDB͔Βඞཁͳ σʔλΛऔಘ͠·͢
  105. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 105 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller ड͚औͬͨσʔλΛ Controllerʹฦ͠·͢
  106. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 106 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller σʔλΛViewʹ౉ͯ͠ ϨεϙϯεͰฦ͢ܗʹՃ޻͠·͢
  107. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 107 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller Controller͔ΒϨεϙϯεΛ ΫϥΠΞϯτʹฦ͠·͢
  108. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 108 ॲཧͷྲྀΕΛMVCʹԊͬͯݟͯΈΑ͏ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller MVCύλʔϯͷྲྀΕ
  109. LaravelͷσΟϨΫτϦͷߏ੒ͷҰ෦ MVCͷσΟϨΫτϦ - app/Http/ ModelͷϑΝΠϧؚ͕·ΕΔʢॾઆ͋Δʣ - app/Http/Controller/ ControllerͷϑΝΠϧؚ͕·ΕΔ - app/resources/views/

    ViewͷϑΝΠϧؚ͕·ΕΔ ͦͷଞͷσΟϨΫτϦ - app/Console/Commands/ ArtisanͷಠࣗΧελϜίϚϯυ - routes/ɹ ϧʔτఆٛϑΝΠϧ - database/ DBͷϚΠάϨʔγϣϯɾॳظ஋ઃఆϑΝΠϧͳͲ - tests/ɹ ςετ - vendor/ɹ ϥΠϒϥϦͳͲʢcomposer ʹΑΔґଘύοέʔδղܾʣ →ઌఔͷॲཧͷྲྀΕʹɺσΟϨΫτϦΛରԠͤͯ͞Έ·͠ΐ͏ LaravelͷσΟϨΫτϦߏ੒ͷ͓͞Β͍ 109
  110. app/ LaravelͷσΟϨΫτϦߏ੒Λ͋ͯ͸ΊΔͱ͜͏ͳΓ·͢ 110 ॲཧͷྲྀΕͱσΟϨΫτϦߏ੒ routes/ DB app/resources/ views app/Http/ Controller

  111. ͔ΜͨΜʹ࣮૷Ͱ͖ͦ͏ʂ ศརͦ͏ʂʂ ࠓͷͱ͜Ζ͸ɺ͜͏ࢥͬͯ΋Β͑ͨΒे෼Ͱ͢ ͔࣍Β࣮ࡍʹΞϓϦέʔγϣϯΛ࡞͍͖ͬͯ·͢ʂ 111

  112. 11࣌20෼·Ͱٳܜ 112

  113. LaravelΛ࢖ͬͯ APIΛ࡞੒͢Δ 113

  114. खΛಈ͔͢࡞ۀͰͷεϥΠυʹ͍ͭͯ ʮ։ൃ؀ڥߏஙʯͱʮLaravelΛ࢖ͬͯAPIΛ࡞੒͢ΔʯͰ͸खΛಈ͔ͯ͠΋ Β͍·͢ɻԼهͷλά͕ग़͍ͯͳ͍εϥΠυ͸࠲ֶͳͷͰɺεϥΠυΛݟͳ͕ ΒߨٛΛฉ͍͍ͯͩ͘͞ɻ ߨٛͷਐΊํʹ͍ͭͯ ࡞ۀ ʮ࡞ۀʯ͕͍͍ͭͯΔεϥΠυ͸࣮ࡍʹखΛಈ͔͠ͳ ͕Βߦ͏ύʔτʹͳΓ·͢ɻ࣮ࡍʹίʔσΟϯάΛ͠ ͨΓɺઃఆͨ͠Γ͢Δ࡞ۀͰग़͖ͯ·͢ɻ ֬ೝ

    ʮ֬ೝʯ͕͍͍ͭͯΔεϥΠυ͸ಈ࡞Λ֬ೝͨ͠Γɺ ฦ͖ͬͯͨ݁ՌΛ֬ೝ͠·͢ 114
  115. ϋϯζΦϯύʔτߨٛதͷλʔϛφϧʹ͍ͭͯ ͜ͷߨٛͰग़ͯ͘ΔλʔϛφϧͰ࣮ߦ͢Δ؀ڥ͸ શͯremote sshͰ઀ଓ͍ͯ͠Δঢ়ଶͰͷVSCodeͷλʔϛφϧͰ͢ɻ खݩͷPCͷλʔϛφϧͰ͸͋Γ·ͤΜɻroot@~ ͱࠨଆʹදࣔ͞Ε͍ͯΔ͜ͱΛ֬ೝ͠·͠ΐ͏ɻ ߨٛͷਐΊํʹ͍ͭͯ 115

  116. λʔϛφϧͰΑ͘࢖͏ίϚϯυ λʔϛφϧ্ͰσΟϨΫτϦΛҠಈͨ͠Γ͠·͢ɻ ͦͷͨΊʹ஌͓ͬͯ͘΂͖ίϚϯυΛࡌ͓͖ͤͯ·͢ɻ ଞʹ΋ΦϓγϣϯͳͲ͋Γ·͕͢ɺຊߨٛͰ͸͜ͷ4ͭͷίϚϯυΛ࢖͏ͱ ͓͍͍֮͑ͯͯͩ͘͞ɻ ߨٛͷਐΊํʹ͍ͭͯ 116 cd # σΟϨΫτϦҠಈ

    cd .. # 1্ͭͷσΟϨΫτϦ֊૚ʹ໭Δ ls # ϑΝΠϧҰཡΛදࣔ pwd # ݱࡏͷσΟϨΫτϦΛදࣔ
  117. ϑΝΠϧͷฤूʹ͍ͭͯ ྘ͷจࣈͰهࡌ͞Ε͍ͯΔՕॴ͸ɺ௥ه͢ΔՕॴͰ͢ɻ ੺͍จࣈͰهࡌ͞Ε͍ͯΔՕॴ͸ɺ࡟আ͢ΔՕॴͰ͢ɻ ૢ࡞͢Δ΂͖ϑΝΠϧΛ֬ೝͯ͠ɺฤूɾอଘ͍ͯͩ͘͠͞ɻ ߨٛͷਐΊํʹ͍ͭͯ 117 ←ؙ͕͍͍ͭͯΔͱ͖͸ɺ มߋ͕อଘ͞Ε͍ͯ·ͤΜɻ ←อଘ͞ΕΔͱɺ ͜ͷΑ͏ʹؙ͕ফ͑·͢

    อଘ͠ͳ͍ͱಈ࡞͠·ͤΜɻ
  118. ΞϓϦέʔγϣϯΛ ηοτΞοϓ͠Α͏ 118

  119. 1೔໨ͰઌʹɺΞϓϦέʔγϣϯηοτΞοϓΛߦͬͨํ΁ ࡞ۀ ※ಈը಺Ͱ͸આ໌͕ͳ͍Ͱ͢ # masterʹ࠷৽Λ͢Δ git pull # ࠶౓ make

    setup/conoha Λ࣮ߦ make setup/conoha ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏
  120. ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏ 120 https://github.com/tosite/gtb-web-application-framework

  121. 12:00 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾgit ͷΠϯετʔϧ ɾڭࡐͷμ΢ϯϩʔυ ɾΞϓϦέʔγϣϯͷηοτΞοϓ ֬ೝ

    ɾΞϓϦέʔγϣϯ͕ϒϥ΢βͰݟΕΔ͜ͱ ࡞ۀλΠϜ ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏ ࡞ۀ 121
  122. ConoHa VPSʹڭࡐΛμ΢ϯϩʔυ͠Α͏ ࡞ۀ git ΛΠϯετʔϧ͠·͢ɻ sudo yum -y install git

    # git͕Πϯετʔϧ͞Ε͍ͯΔ͜ͱΛ֬ೝ͠·͢ git --version # ੒ޭ git version 1.8.3.1 ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏
  123. ConoHa VPSʹڭࡐΛμ΢ϯϩʔυ͠Α͏ ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏ ࡞ۀ μ΢ϯϩʔυͨ͠ڭࡐͷσΟϨΫτϦʹҠಈ͠·͢ɻ σΟϨΫτϦΛҠಈɾڭࡐΛμ΢ϯϩʔυ͠·͢ɻ cd /var/www/html git clone

    https://github.com/tosite/gtb-web-application-framework.git cd /var/www/html/gtb-web-application-framework pwd # ͜ͷΑ͏ʹදࣔ͞Ε͍ͯΔ͜ͱΛ֬ೝ͍ͯͩ͘͠͞ /var/www/html/gtb-web-application-framework ΋͠ cd /var/www/html ͰΤϥʔ͕ͰͨΒVPSͷॳظઃఆ͕ؒҧ͍ͬͯΔՄೳੑ͕͋ΔͷͰ खΛڍ͛ͯڭ͍͑ͯͩ͘͞
  124. ConoHa VPSʹڭࡐΛηοτΞοϓ͠Α͏ ࡞ۀ ڭࡐΛηοτΞοϓ͠·͢ɻ make setup/conoha ิ଍ɿmakeίϚϯυͰΞϓϦέʔγϣϯͷηοτΞοϓΛࣗಈԽ͍ͯ͠·͢ɻڵຯͷ͋Δਓ͸֬ೝͯ͠Έ·͠ΐ͏ɻ - https://github.com/tosite/gtb-web-application-framework ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏

  125. VSCodeଆͰ࡞ۀσΟϨΫτϦΛมߋ͠Α͏ VSCodeଆͰʮϑΝΠϧʯˠʮOpenʯΛબ୒͍ͯͩ͘͠͞ɻ /var/www/html/gtb-web-application-framework Λೖྗͯ͠OKΛೖΕ͍ͯͩ͞ɻ ࡞ۀ 125 ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏

  126. VSCodeଆͰ࡞ۀσΟϨΫτϦΛมߋ͠Α͏ σΟϨΫτϦ͕มΘ͍ͬͯΔ͜ͱΛ֬ೝ͠·͢ɻ͜ΕͰϑΝΠϧΛฤू͢Δ४උ͕੔͍·ͨ͠ɻ ࡞ۀ 126 ΞϓϦέʔγϣϯΛηοτΞοϓ͠Α͏

  127. 14࣌00෼·Ͱ ͓னٳܜ 127

  128. API TesterΛ࢖ͬͯΈΑ͏ 128

  129. APIը໘ ͜͜Ͱओʹ࡞੒ͨ͠APIͷಈ࡞ݕূΛߦ͍·͢ɻResultʹϨεϙϯε͕ฦ͖ͬͯ·͢ɻ API TesterΛ࢖ͬͯΈΑ͏ ֬ೝ 129

  130. Routesը໘ ϧʔςΟϯάͱίϯτϩʔϥʔͷରԠΛݟΔ͜ͱ͕Ͱ͖·͢ɻ API TesterΛ࢖ͬͯΈΑ͏ ֬ೝ 130

  131. Logsը໘ ΤϥʔϩάΛݟΔ͜ͱ͕Ͱ͖·͢ɻ API TesterΛ࢖ͬͯΈΑ͏ ֬ೝ 131

  132. σʔλΛશදࣔ ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ API TesterΛ࢖ͬͯΈΑ͏ 132 Selected Method get Uri /api/comments

    Parameters ͳ͠ ֬ೝ
  133. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ σʔλΛશදࣔ API TesterΛ࢖ͬͯΈΑ͏ 133 Selected Method get Uri /api/comments

    Parameters ͳ͠ ֬ೝ 200 ʢσʔλදࣔʹ੒ޭʣ
  134. API TesterΛ࢖ͬͯΈΑ͏ ֬ೝ 134

  135. 12:10·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾAPIςελʔͰGETϦΫΤετΛૹΔ ֬ೝ ɾεςʔλε200͕ฦͬͯ͘Δ͜ͱ ɾίϝϯτͷҰཡͷύϥϝʔλ͕ݟΕΔ͜ͱ ࡞ۀλΠϜ API

    TesterΛ࢖ͬͯΈΑ͏ ࡞ۀ 135
  136. POSTͰϦΫΤετ͢Δͱࣦഊ͢Δ͔֬ೝ͠Α͏ Parametersͷkey͸ʮnameʯͱʮcontentʯΛ௥Ճ͍ͯͩ͘͠͞ API TesterΛ࢖ͬͯΈΑ͏ ֬ೝ 136

  137. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ POSTͰϦΫΤετ͢Δͱࣦഊ͢Δ͔֬ೝ͠Α͏ API TesterΛ࢖ͬͯΈΑ͏ 137 Selected Method post Uri /api/comments

    Parameters name: ࣗ༝ content: ࣗ༝ ֬ೝ
  138. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ POSTͰϦΫΤετ͢Δͱࣦഊ͢Δ͔֬ೝ͠Α͏ API TesterΛ࢖ͬͯΈΑ͏ 138 Selected Method post Uri /api/comments

    Parameters name: ࣗ༝ content: ࣗ༝ ֬ೝ 405 Τϥʔ
  139. API TesterΛ࢖ͬͯΈΑ͏ ֬ೝ 139

  140. 12:15·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɹPOSTϦΫΤετΛૹΔ ֬ೝ ɾεςʔλε405ͰΤϥʔ͕ฦͬͯ͘Δ͜ͱ ࡞ۀλΠϜ API TesterΛ࢖ͬͯΈΑ͏

    ࡞ۀ 140
  141. **࣌**෼·Ͱٳܜ 141

  142. 13࣌45෼·Ͱ ͓னٳܜ 142

  143. APIͷCRUDΛ࣮૷͠Α͏ લ൒(Create,Read) 143

  144. Create 144

  145. routes/api.phpΛVSCodeͰ։͍ͯΈΑ͏ɻ CRUDͷCreate - ϧʔςΟϯάʹ௥Ճ͢Δ APIͷCRUDΛ࣮૷͠Α͏ 145 ֬ೝ <?php use Illuminate\Http\Request;

    Route::middleware('api')->group(function () { Route::delete('logs', function () { exec(': > ../storage/logs/laravel.log'); }); Route::get('comments', 'CommentController@index'); Route::post('comments', 'CommentController@store'); });
  146. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷCreate - Ϩεϙϯε͕ฦͬͯ͘Δ͔֬ೝ APIͷCRUDΛ࣮૷͠Α͏ 146 Selected Method post Uri

    /api/comments Parameters name: ࣗ༝ content: ࣗ༝ ֬ೝ
  147. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷCreate - Ϩεϙϯε͕ฦͬͯ͘Δ͔֬ೝ APIͷCRUDΛ࣮૷͠Α͏ 147 Selected Method post Uri

    /api/comments Parameters name: ࣗ༝ content: ࣗ༝ ֬ೝ 200 ʢϧʔςΟϯάʹ੒ޭʣ
  148. ҎԼͷΤϥʔ͕ग़ͨ৔߹ɺParameters͕ෆద੾ͳՄೳੑ͕ߟ͑ΒΕ·͢ɻ ۭͰͳ͍͜ͱΛ֬ೝͯ͠࠶౓࣮ߦ͍ͯͩ͘͠͞ɻ CRUDͷCreate - Ϩεϙϯε͕ฦͬͯ͘Δ͔֬ೝ APIͷCRUDΛ࣮૷͠Α͏ 148 Selected Method post

    Uri /api/comments Parameters name: ۭ content: ۭ ֬ೝ 422 Τϥʔ
  149. APIͷCRUDΛ࣮૷͠Α͏ ֬ೝ 149

  150. 14:20 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾίϝϯτొ࿥ͷϧʔςΟϯάΛ௥Ճ͢Δ ɾAPIςελʔͰ࠶ͼPOSTϦΫΤετΛૹΔ ֬ೝ ɾύϥϝʔλΛೖྗͯ͠ϦΫΤετΛߦ͏ͱε ςʔλε200͕ฦͬͯ͘Δ͜ͱ

    ࡞ۀλΠϜ APIͷCRUDΛ࣮૷͠Α͏ ࡞ۀ 150
  151. λʔϛφϧͰartisanίϚϯυΛ࣮ߦͯ͠Έ·͠ΐ͏ɻ Model͸{Ϟσϧ໊}.phpͱ͍͏ϑΝΠϧ໊Ͱ࡞੒͞Ε·͢ɻ Comment Model Λ artisan ίϚϯυͰ࡞੒ APIͷCRUDΛ࣮૷͠Α͏ 151 pwd

    # ͜Ε͕දࣔ͞ΕΔ͜ͱΛ֬ೝ͍ͯͩ͘͠͞ /var/www/html/gtb-web-application php artisan make:model Comment # ੒ޭ Model created successfully. ࡞ۀ
  152. Model Λ artisan ίϚϯυͰ࡞੒ APIͷCRUDΛ࣮૷͠Α͏ 152 ֬ೝ

  153. Model ECγϣοϓ͔Β෰ͷҰཡσʔλΛऔಘ͍ͨ͠৔߹ͷྫ 153 MVCύλʔϯͷಛ௃ʢ෮शʣ Route DB View ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ ᶉ Controller MVCύλʔϯͷྲྀΕ
  154. Modelʹ$fillableΛ௥Ճͯ͠nameͱcontentΛ௥Ճ͠·͢ɻ app/Comment.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ Model ʹ $fillable Λ௥Ճ͢Δ APIͷCRUDΛ࣮૷͠Α͏ 154 <?php namespace

    App; use Illuminate\Database\Eloquent\Model; class Comment extends Model { protected $fillable = [ 'name', 'content', ]; } ࡞ۀ
  155. app/Http/Controllers/CommentController.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷCreate - ControllerʹstoreͷॲཧΛ௥Ճ APIͷCRUDΛ࣮૷͠Α͏ 155 public function store(\App\Http\Requests\Comments\Post $request)

    { $comment = Comment::create([ 'name' => $request->input('name'), 'content' => $request->input('content'), ]); return response()->json($comment, 201); } ࡞ۀ
  156. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷCreate - ࠶࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 156 Selected Method post Uri

    /api/comments Parameters name: ࣗ෼ content: ࣗ༝ ֬ೝ 201 ʢDBʹϨίʔυ௥Ճʣ
  157. ҎԼͷΑ͏ͳϨεϙϯε͕ฦͬͯ͘Δ͜ͱΛ֬ೝ͠·͠ΐ͏ɻ CRUDͷCreate - ࠶࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 157 ֬ೝ id Λ߇͓͑ͯ͘

  158. APIͷCRUDΛ࣮૷͠Α͏ ֬ೝ 158

  159. 14:45 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾCommentϞσϧΛ࡞੒͢Δ ɾ$fillableͰΧϥϜߋ৽ͷڐՄΛઃఆ͢Δ ɾσʔλΛొ࿥͢ΔॲཧΛ௥Ճ͢Δ ɾAPIςελʔͰ࠶ͼPOSTϦΫΤετΛૹΔ ֬ೝ

    ɾεςʔλε201͕ฦͬͯ͘Δ͜ͱ ɾύϥϝʔλ͕ݟΕΔ͜ͱʢidΛ߇͓͑ͯ͘ʣ ࡞ۀλΠϜ APIͷCRUDΛ࣮૷͠Α͏ ࡞ۀ 159
  160. Read 160

  161. routes/api.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷRead - ϧʔςΟϯάʹ௥Ճ͢Δ APIͷCRUDΛ࣮૷͠Α͏ 161 <?php use Illuminate\Http\Request; Route::middleware('api')->group(function

    () { Route::delete('logs', function () { exec(': > ../storage/logs/laravel.log'); }); Route::get('comments', 'CommentController@index'); Route::post('comments', 'CommentController@store'); Route::get('comments/{comment}', 'CommentController@show'); }); ࡞ۀ
  162. ࡞ۀ app/Http/Controllers/CommentController.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷRead - ControllerʹshowͷॲཧΛ௥Ճ APIͷCRUDΛ࣮૷͠Α͏ 162 public function show($id)

    { return Comment::findOrFail($id); }
  163. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ {id}ʹ͸ઌ΄Ͳ߇͑ͨidΛೖྗ͠·͢ɻ CRUDͷRead - Ϩεϙϯε͕ฦͬͯ͘Δ͔֬ೝ APIͷCRUDΛ࣮૷͠Α͏ 163 Selected Method get

    Uri /api/comments/ {id} Parameters ͳ͠ ࡞ۀ
  164. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ {id}ʹ͸ઌ΄Ͳ߇͑ͨidΛೖྗ͠·͢ɻ CRUDͷRead - Ϩεϙϯε͕ฦͬͯ͘Δ͔֬ೝ APIͷCRUDΛ࣮૷͠Α͏ 164 Selected Method get

    Uri /api/comments/ {id} Parameters ͳ͠ ࡞ۀ 200 Createͨ͠σʔλ͕ දࣔ͞ΕΔ
  165. APIͷCRUDΛ࣮૷͠Α͏ ֬ೝ 165

  166. 15:10·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾࢦఆͨ͠idͷίϝϯτΛදࣔ͢ΔͨΊͷ ɹϧʔςΟϯάͱॲཧΛ௥Ճ͢Δ ɾࢦఆͨ͠idͷίϝϯτΛදࣔ͢ΔGET ɹϦΫΤετΛૹΔ ֬ೝ ɾεςʔλε200͕ฦͬͯ͘Δ͜ͱ

    ɾࢦఆͨ͠idͷσʔλ͕֬ೝͰ͖Δ͜ͱ ࡞ۀλΠϜ APIͷCRUDΛ࣮૷͠Α͏ ࡞ۀ 166
  167. 15࣌05෼·Ͱٳܜ 167

  168. APIͷCRUDΛ࣮૷͠Α͏ ޙ൒(Update,Delete,Index) 168

  169. Update 169

  170. routes/api.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷUpdate - ϧʔςΟϯάʹ௥Ճ APIͷCRUDΛ࣮૷͠Α͏ 170 <?php use Illuminate\Http\Request; Route::middleware('api')->group(function

    () { Route::delete('logs', function () { exec(': > ../storage/logs/laravel.log'); }); Route::get('comments', 'CommentController@index'); Route::post('comments', 'CommentController@store'); Route::get('comments/{comment}', 'CommentController@show'); Route::put('comments/{comment}', 'CommentController@update'); }); ࡞ۀ
  171. CRUDͷUpdate - ControllerʹupdateͷॲཧΛ௥Ճ app/Http/Controllers/CommentController.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ APIͷCRUDΛ࣮૷͠Α͏ 171 public function update(\App\Http\Requests\Comments\Put $request,

    $id) { $comment = Comment::findOrFail($id); $comment->update([ 'name' => $request->input('name') ?: $comment->name, 'content' => $request->input('content') ?: $comment->content, ]); return response()->json($comment, 200); } ࡞ۀ
  172. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷUpdate - ࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 172 Selected Method put/patch Uri

    /api/comments/ {id} Parameters name: ࣗ༝ ࡞ۀ
  173. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷUpdate - ࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 173 Selected Method put/patch Uri

    /api/comments/ {id} Parameters name: ࣗ༝ ࡞ۀ 200 name͕ߋ৽͞ΕΔ
  174. APIͷCRUDΛ࣮૷͠Α͏ ֬ೝ 174

  175. 15:45 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾߋ৽ͷϧʔςΟϯάΛ௥Ճ͢Δ ɾߋ৽ͷॲཧΛ௥Ճ͢Δ ɾAPIςελʔͰࢦఆͨ͠idͷ಺༰Λมߋ͢Δ ϦΫΤετΛૹΔ ֬ೝ

    ɾεςʔλε200͕ฦͬͯ͘Δ͜ͱ ɾมߋͷ಺༰͕֬ೝͰ͖Δ͜ͱ ࡞ۀλΠϜ APIͷCRUDΛ࣮૷͠Α͏ ࡞ۀ 175
  176. Delete 176

  177. routes/api.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷDelete - ϧʔςΟϯάʹ௥Ճ APIͷCRUDΛ࣮૷͠Α͏ 177 <?php use Illuminate\Http\Request; Route::middleware('api')->group(function

    () { Route::delete('logs', function () { exec(': > ../storage/logs/laravel.log'); }); Route::get('comments', 'CommentController@index'); Route::post('comments', 'CommentController@store'); Route::get('comments/{comment}', 'CommentController@show'); Route::put('comments/{comment}', 'CommentController@update'); Route::delete('comments/{comment}', 'CommentController@destroy'); }); ࡞ۀ
  178. app/Http/Controllers/CommentController.phpΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷDelete - ControllerʹdestroyͷॲཧΛ௥Ճ APIͷCRUDΛ࣮૷͠Α͏ 178 public function destroy($id) {

    Comment::findOrFail($id)->delete(); return response()->noContent(); } ࡞ۀ
  179. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷDelete - ࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 179 Selected Method delete Uri

    /api/comments/ {id} Parameters ͳ͠ ࡞ۀ
  180. APIͷCRUDΛ࣮૷͠Α͏ ֬ೝ 180

  181. 16:05 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾ࡟আͷϧʔςΟϯάΛ௥Ճ͢Δ ɾ࡟আͷॲཧΛ௥Ճ͢Δ ɾAPIςελʔͰࢦఆͨ͠idͷσʔλΛ࡟আ͢Δ ɹϦΫΤετΛૹΔ ֬ೝ

    ɾεςʔλε204͕ฦͬͯ͘Δ͜ͱ ɾidΛࢦఆͯ͠GETͯ͠ݟΕͳ͍͜ͱ ࡞ۀλΠϜ APIͷCRUDΛ࣮૷͠Α͏ ࡞ۀ 181
  182. Index 182

  183. app/Http/Controllers/CommentController.php ΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ CRUDͷRead - ControllerʹshowͷॲཧΛ௥Ճ APIͷCRUDΛ࣮૷͠Α͏ 183 public function index()

    { return [ ['name' => 'tom', 'content' => 'hello'], ['name' => 'sam', 'content' => 'world'], ]; return Comment::all(); } ࡞ۀ
  184. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷRead - API࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 184 Selected Method get Uri

    /api/comments Parameters ͳ͠ ֬ೝ
  185. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ CRUDͷRead - API࣮ߦ APIͷCRUDΛ࣮૷͠Α͏ 185 Selected Method get Uri

    /api/comments Parameters ͳ͠ ֬ೝ 200 σʔλ͕දࣔ͞ΕΔ
  186. APIͷCRUDΛ࣮૷͠Α͏ ֬ೝ 186

  187. 16:15 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾίϝϯτҰཡΛऔಘ͢ΔॲཧΛ௥Ճ͢Δ ɾAPIςελʔͰҰཡΛऔಘ͢ΔϦΫΤετΛ ɹૹΔ ֬ೝ ɾεςʔλε200͕ฦͬͯ͘Δ͜ͱ

    ɾίϝϯτҰཡ͕ݟΕΔ͜ͱ ࡞ۀλΠϜ APIͷCRUDΛ࣮૷͠Α͏ ࡞ۀ 187
  188. 16࣌05෼·Ͱٳܜ 188

  189. ORMͷΑ΋΍·࿩ 189

  190. ORMͱ͸Object-Relational MappingͷུশͰ͢ɻ LaravelͰ͸Eloquentͱݺ͹ΕΔORM͕࢖ΘΕ͍ͯ·͢ɻ RailsͰ͸Active Record͕࢖ΘΕ͍ͯ·͢ɻ ࢼ͠ʹapp/Http/Controllers/CommentController.php ΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ ͜͜Ͱ͸CommentΫϥε͕ORMͷ໾ׂΛՌ͍ͨͯ͠·͢ɻ ࢀߟࢿྉ:ʮEloquent:ར༻ͷ։࢝ʯhttps://readouble.com/laravel/6.x/ja/eloquent.html ORMʹ͍ͭͯ؆୯ʹ঺հ

    ORMͷΑ΋΍·࿩ 190 public function show($id) { return Comment::findOrFail($id); }
  191. ORMΛ࢖༻͢Δ͜ͱʹΑͬͯɺҎԼͷΑ͏ͳԸܙΛड͚Δ͜ͱ͕Ͱ͖·͢ɻ 1. SQLΛॻ͔ͣ௚ײతʹDBΛૢ࡞Ͱ͖Δ 2. ϦϨʔγϣϯΛ࢖ͬͨૢ࡞ָ͕ʹॻ͚Δ 3. SQLΠϯδΣΫγϣϯͳͲͷ߈ܸʹରͯࣗ͠ಈͰ๷͍Ͱ͘ΕΔ 4. औಘͨ͠σʔλ͕ΦϒδΣΫτͳͷͰฤू͕͠΍͍͢ ORMͷར఺ʹ͍ͭͯ঺հ

    ORMͷΑ΋΍·࿩ 191
  192. σʔλΛऔಘ͢Δ৔߹ͷྫ(SELECT) ҎԼ͸ಉٛͰ͢ɻ SQLΛॻ͔ͣ௚ײతʹDBΛૢ࡞Ͱ͖Δ ORMͷΑ΋΍·࿩ 192 SELECT * FROM comments; SELECT

    * FROM comments where id = 1; App\Comment::all(); App\Comment::where(‘id’, 1)->get(); SQL ORM
  193. σʔλΛ௥Ճ͢Δ৔߹ͷྫ(INSERT) ҎԼ͸ಉٛͰ͢ɻ SQLΛॻ͔ͣ௚ײతʹDBΛૢ࡞Ͱ͖Δ ORMͷΑ΋΍·࿩ 193 INSERT INTO comments VALUE (

    name = ‘tosite’, content = ‘body text’, email = ‘sample@example.com’ ); $params = [name => ‘tosite’, content => ‘body text’, email => ‘sample@example.com’,]; (new Comments())->fill($params)->save(); SQL ORM
  194. app/Http/Controllers/CommentController.php ΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ findOrFailϝιου͸֘౰͢ΔϨίʔυ͕ݟ͔ͭΒͳ͍࣌ɺࣗಈͰ404 HTTPϨεϙϯεΛฦͯ͘͠Ε·͢ɻ ͳͷͰ͜ͷϝιουΛ࢖༻͢Ε͹Θ͟Θ͟໌֬ʹ404ϨεϙϯεΛฦ͢ίʔυΛॻ͘ඞཁ͸͋Γ·ͤΜɻ ͜ͷ৔߹͸API TesterͰଘࡏ͠ͳ͍IDΛࢦఆͯ͠ϦΫΤετΛ͢ΔͱࣗಈͰ404͕ฦ͖ͬͯ·͢ɻ findOrFail ORMͷΑ΋΍·࿩ 194

    public function show($id) { return Comment::findOrFail($id); } ORM
  195. findOrFail ORMͷΑ΋΍·࿩ 195

  196. UserϞσϧͱCommentϞσϧ͕1ରNͷؔ܎ʹͳ͍ͬͯΔͱԾఆ͠·͢ɻ (※commentsςʔϒϧ಺ʹuser_idΛอ͍࣋ͯ͠Δ৔߹) ϦϨʔγϣϯΛ࢖ͬͨૢ࡞ָ͕ ORMͷΑ΋΍·࿩ 196 User hasOne = 1:1 hasMany

    = 1:N belongsTo = N:1 belongsToMany = N:N Comment Comment Comment User has many Comments
  197. UserϞσϧͱCommentϞσϧ͕1ରNͷؔ܎ʹͳ͍ͬͯΔͱԾఆ͠·͢ɻ (※commentsςʔϒϧ಺ʹuser_idΛอ͍࣋ͯ͠Δ৔߹) ϦϨʔγϣϯΛ࢖ͬͨૢ࡞ָ͕ ORMͷΑ΋΍·࿩ 197 class User extends Model {

    public function comments() { return $this->hasMany('App\Comment'); } }
  198. σʔλΛऔಘ͢Δ৔߹ͷྫ(SELECT) ҎԼ͸ಉٛͰ͢ɻ ϦϨʔγϣϯΛ࢖ͬͨૢ࡞ָ͕ ORMͷΑ΋΍·࿩ 198 SELECT * FROM users LEFT

    JOIN commnets ON comments.user_id = users.user_id User::comments(); SQL ORM
  199. ※੺͘৭Λ෇͚͍ͯΔ෦෼ʹ੬ऑੑ͕જΜͰ͍·͢ɻ ηΩϡϦςΟରࡦ ORMͷΑ΋΍·࿩ 199 $res = pg_query( $dbconn, “select *

    from users where id = ‘{$_POST[‘id’]}’ and password = ‘{$_POST[‘password’]}’”, ); Users::where(‘id’, $_POST[‘id’])->where(‘password’, $_POST[‘password’])->get(); SQL + PHP ORM
  200. WebΞϓϦέʔγϣϯͰ࣮ߦ͞ΕΔSQLจʹ͓͍ͯɺϢʔβʔ͔Βͷ ೖྗΛར༻͢Δ͜ͱ͕ଟ͍Ͱ͢ɻ - ྫ͑͹ձһ੍αΠτͰϩάΠϯΛߦ͏৔߹ - Ϣʔβʔ͔ΒID/ύεϫʔυΛड͚औΔ - ड͚औͬͨจࣈྻΛݩʹձһςʔϒϧʹରͯ͠SQLจΛൃߦ͢Δ - ͔͠͠ͳ͕ΒɺϢʔβʔ͸ળҙͷϢʔβʔ͹͔ΓͰ͸ͳ͍

    ηΩϡϦςΟରࡦ ORMͷΑ΋΍·࿩ 200
  201. ઌ΄ͲͷྫΛݩʹߟ͑ͯΈ·͠ΐ͏ɻ Ωʔϫʔυ͸ʮϢʔβʔ͔ΒͷೖྗΛશ໘తʹ৴͡Δͱ௧͍໨ʹૺ͏ʯͰ͢ɻ ͜ͷΑ͏ʹSQLΛվม͢Δ߈ܸΛʮSQLΠϯδΣΫγϣϯ߈ܸʯͱݴ͍·͢ɻ ηΩϡϦςΟରࡦ ORMͷΑ΋΍·࿩ 201 # ϩάΠϯ࣌ͷೝূͰ࢖༻͢ΔSQLจΛ࣍ͷΑ͏ʹ࡞੒͍ͯͨ͠ͱ͢Δ $res =

    pg_query( $dbconn, “select * from users where id = ‘{$_POST[‘id’]}’ and password = ‘{$_POST[‘password’]}”, ); # Ծʹ$_POST[‘id’]ʹʮ' or '1' = '1';-- ʯͱ͍͏஋͕౉͞Εͨ৔߹ɺҎԼͷΫΤϦ͕ൃߦ͞ΕΔ # ҎԼͷΫΤϦ͸྘৭ͷ෦෼͕ඞͣ੒ཱͯ͠͠·͏ͨΊɺશϢʔβʔͷ৘ใΛݕࡧͰ͖Δ SELECT * FROM users WHERE id = ‘’ or ‘1’ = ‘1’;-- ’ and password = ‘foo’; SQL + PHP
  202. Ͱ͸SQLΠϯδΣΫγϣϯΛͲͷΑ͏ʹ๷͙ͷ͔ʁΛݟͯΈ·͠ΐ͏ɻ େ੾ͳͷ͸ʮϓϦϖΞυεςʔτϝϯτʯΛར༻͢Δͱ͍͏͜ͱͰ͢ɻ ϓϦϖΞυεςʔτϝϯτΛ࢖͏ϝϦοτ - σʔλϕʔεʹ४උ͞Ε͍ͯΔػೳͰɺSQLจͷ૊ΈཱͯࢧԉΛߦͬͯ͘ΕΔ - SQLจ಺ͷՄม෦෼Λൈ͖ग़ͯ͠ɺͦ͜ʹରͯ͠஋ͷઃఆΛߦ͏͜ͱ͕Ͱ͖Δ - ஋Λઃఆ͢ΔࡍʹΤεέʔϓॲཧ͕࣮ࢪ͞ΕΔ -

    ܕνΣοΫ͕ߦΘΕΔ͜ͱ΋͋Δ ηΩϡϦςΟରࡦ ORMͷΑ΋΍·࿩ 202 $res = pg_query( $dbconn, ‘select * from users where id = $1 and password = $2’, array($_POST[‘id’], $_POST[‘password’]) );
  203. ΋͏Ұͭͷํ๏ͱͯ͠ɺORMΛར༻͢Δͱ͍͏ํ๏͕͋Γ·͢ɺ ORMΛ࢖͏ϝϦοτ - ORM͸಺෦తʹϓϦϖΞυεςʔτϝϯτΛར༻͍ͯ͠Δ͜ͱ͕΄ͱΜͲ - ஋Λઃఆ͢ΔࡍʹΤεέʔϓॲཧ͕࣮ࢪ͞ΕΔ - ܕνΣοΫ͕ߦΘΕΔ͜ͱ΋͋Δ ηΩϡϦςΟରࡦ ORMͷΑ΋΍·࿩

    203 User::where(‘id’, ‘tosite’)->where(‘password’, ‘password1234’)->first();
  204. ݁࿦ - SQLͷ૊ΈཱͯͰจࣈྻ࿈͚݁ͩ͸ઈରʹͯ͠͸͍͚ͳ͍ - ֎෦͔Βͷೖྗ͸৴ͯ͡͸͍͚ͳ͍ ηΩϡϦςΟରࡦ ORMͷΑ΋΍·࿩ 204

  205. Q. Ͱ͸ORMΛੵۃతʹ࢖ͬͨ΄͏͕͍͍ͷ͔ʁ ORMͷΑ΋΍·࿩ 205

  206. ҎԼͷέʔε͕֘౰͢ΔՄೳੑ͕͋Γ·͢ɻ 1. ෳ਺ͷςʔϒϧΛ·͙ͨॲཧΛORMͰ࣮૷Λ͠Α͏ͱ͢Δͱ ࣮૷͕೉͘͠ͳΔέʔε 1. ORMͷཪଆͰൃߦ͍ͯ͠ΔSQL͕ҙਤͤͣN+1໰୊ΛҾ͖ى͜͢έʔε A. ৔߹ʹΑΔɻORMΛ࢖Θͳ͍ํ͕ྑ͍৔߹΋౰વ͋Δɻ ORMͷΑ΋΍·࿩ 206

  207. N+1໰୊ΛҾ͖ى͜͢έʔε ORMͷΑ΋΍·࿩ 207 # ORM class Comment extends Model {

    public function user() { return $this->belongsTo('App\User'); } } # Controller $comments = Comment::all(); foreach ($comments as $comment) { echo $comment->user; }
  208. ϖʔδΛදࣔ͢ΔͨͼʹҎԼͷΫΤϦ͕ൃߦ͞ΕΔ͜ͱʹͳΓ·͢ɻ ͜Ε͸ $comments->user ͕࣮ߦ͞ΕΔ౓ʹSQL͕ൃߦ͞ΕΔ͜ͱʹىҼ͠·͢ɻ ΋ͪΖΜɺORMଆͰରࡦ͢Δ͜ͱ͸ՄೳͰ͢ɻ N+1໰୊ΛҾ͖ى͜͢έʔε ORMͷΑ΋΍·࿩ 208 select *

    from comments; select * from users where id = 1; select * from users where id = 2; select * from users where id = 3; -- ҎԼϨίʔυ͕ଘࡏ͢Δ෼͚ͩΫΤϦ͕ൃߦ͞ΕΔ $comments = Comment::with('user')->get(); foreach ($comments as $ comment) { echo $comment->user }
  209. ORMΛ࢖ͬͨํ๏͚ͩΛཧղ͢ΔͷͰ͸ͳ͘ɺཪଆͰൃߦ͞ΕΔSQLͷҙຯΛ ཧղ͢ΔͨΊʹ΋ɺૉͷSQLΛ͔ͬ͠Γॻ͚ΔΑ͏ʹֶͼ·͠ΐ͏! ·ͱΊ ORMͷΑ΋΍·࿩ 209

  210. 16࣌45෼·Ͱٳܜ 210

  211. ValidationΛ࣮૷͠Α͏ 211

  212. Validationͳ͠ͷ৔߹ ValidationΛ࣮૷͠Α͏ 212 WebΞϓϦέʔγϣϯ ར༻ऀͷݸਓ৘ใ ѱҙΛ࣋ͬͨϢʔβʔ ѱҙͷ͋ΔϦΫΤετ ਖ਼ৗͳϨεϙϯε ਖ਼ৗͳϦΫΤετͩͱצҧ͍ͯ͠ ਖ਼ৗͳϨεϙϯεΛฦͯ͠͠·͏

    ݁Ռɺଞਓͷݸਓ৘ใʹΞΫηε ͞Εͯ৘ใΛ࣋ͪग़͞ΕΔ
  213. Validation͋Γͷ৔߹ ValidationΛ࣮૷͠Α͏ 213 WebΞϓϦέʔγϣϯ ѱҙΛ࣋ͬͨϢʔβʔ ѱҙͷ͋ΔϦΫΤετ ѱҙͷ͋ΔϦΫΤετ͸ࣄલʹ ๷͕ΕΔ ར༻ऀͷݸਓ৘ใ

  214. - HTTPϦΫΤετͰड͚औΔೖྗ͕ࣗ෼ͷ૝ఆ௨Γʹ͘Δͱࢥ͍ࠐ·ͳ͍ - ྫ͑͹HTMLͷηϨΫτϘοΫεͷબ୒ࢶͱͯ͠ʮ1ʯʮ10ʯʮ50ʯΛ ४උ͍ͯͨ͠৔߹ʹ͜ͷ3ͭͷ஋͔͠དྷͳ͍ͱࢥͬͨΒେؒҧ͍ - ߈ܸऀ͸ૉ௚ʹϒϥ΢βͰϦΫΤετͳΜ͔͠ͳ͍ - Ͳͷϒϥ΢β͔ΒͷΞΫηεͳͷ͔Λද͢User-Agentͱ͍͏΋ͷ΋ ِ૷Մೳ

    - ૬ख͕ຊ౰ʹ Chrome Λ࢖͍ͬͯΔ͔͸Θ͔Βͳ͍ ֎෦͔Βͷೖྗ͸৴ͯ͡͸͍͚ͳ͍ʢେࣄͳ͜ͱͳͷͰ2ճ͈́ʣ ValidationΛ࣮૷͠Α͏ 214
  215. - ةݥͩͱ൑அͨ͠΋ͷΛແ֐Խ͢Δ͜ͱΛʮαχλΠζʯͱ͍͏ - ׬શʹαχλΠζ͸Ͱ͖ͳ͍ͱࢥ͓͍ͬͯͨ΄͏͕ྑ͍ - ߈ܸऀ͸͞Βʹ޼ົʹ஋Λِ૷ͯ͘͠Δ - ෆໟͳΠλνͬ͜͝Λ͢ΔΑΓ΋ո͍͠΋ͷ͸ड͚෇͚ͣʹڋ൱͢Δ ո͍͠΋ͷ͸ड͚෇͚ͳ͍ ValidationΛ࣮૷͠Α͏

    215
  216. ո͍͠΋ͷ͸ड͚෇͚ͳ͍ - ֎෦͔ΒͷೖྗΛ࢖ͬͯͦͷ··SQLΛ૊ΈཱͯΔ - ʮSQLΠϯδΣΫγϣϯʯ͕ى͖Δ - ֎෦͔ΒͷೖྗΛ࢖࣮ͬͯߦ͢ΔίϚϯυΛ૊ΈཱͯΔ - ʮίϚϯυΠϯδΣΫγϣϯʯ͕ى͖Δ -

    ֎෦͔ΒͷೖྗΛ࢖ͬͯHTMLΛग़ྗͯ͠͠·͏ - ʮΫϩεαΠτεΫϦϓςΟϯά(XSS)ʯ͕ى͖Δ ֎෦͔ΒͷೖྗΛ৴͡ΔͱͲ͏ͳΔͷ͔ʁ ValidationΛ࣮૷͠Α͏ 216
  217. ֎෦͔Βͷೖྗ͸৴ͯ͡͸͍͚ͳ͍ʢ3ճ໨ʣ - ո͍͠ͱࢥΘΕΔೖྗ͸ແ֐Խͯ͠࢖͏ͷͰ͸ͳ͘ ͦ͏͍͏ೖྗ͸ڋ൱͢Δ - Τϥʔѻ͍ʹ͢Δ ݁࿦ ValidationΛ࣮૷͠Α͏ 217

  218. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ ValidationʹҾ͔͔ͬΔΑ͏ʹAPIΛ࣮ߦ͢Δ ValidationΛ࣮૷͠Α͏ 218 Selected Method put/patch Uri /api/comments/ {id}

    Parameters name: ࣗ෼ content: ʢۭʣ ֬ೝ
  219. ҎԼͷύϥϝʔλΛೖྗޙɺSUBMITΛԡ͍ͯͩ͘͠͞ɻ ValidationʹҾ͔͔ͬΔΑ͏ʹAPIΛ࣮ߦ͢Δ ValidationΛ࣮૷͠Α͏ 219 Selected Method put/patch Uri /api/comments/ {id}

    Parameters name: ࣗ෼ content: ʢۭʣ ֬ೝ 422 The content field is required.
  220. ࠓͷValidationͷ࣮૷ΛΈͯΈΑ͏ app/Http/Request/Comments/Post.php ΛVSCodeͰ։͍ͯΈ·͠ΐ͏ɻ ValidationΛ࣮૷͠Α͏ 220 public function rules() { return

    [ 'name' => 'required', // nameύϥϝʔλ͸ඞਢೖྗ 'content' => 'required', // contentύϥϝʔλ͸ඞਢೖྗ ]; } ֬ೝ
  221. ValidationͷυΩϡϝϯτΛݟͯϧʔϧ௥Ճ͠Α͏ min:஋ = ࢦఆ͞Εͨ஋Ҏ্Ͱ͋Δ͜ͱΛόϦσʔτ͠·͢ɻ max:஋ = ࢦఆ͞Εͨ஋ҎԼͰ͋Δ͜ͱΛόϦσʔτ͠·͢ɻ ࢀߟࢿྉɿόϦσʔγϣϯʹ͍ͭͯ https://readouble.com/laravel/6.x/ja/validation.html ValidationΛ࣮૷͠Α͏

    ࡞ۀ 221 public function rules() { return [ 'name' => 'required|min:5|max:10', 'content' => 'required', ]; }
  222. nameʹ4จࣈ·ͨ͸11จࣈͷจࣈྻೖΕࣦͯഊ͢ΔͷΛ֬ೝ͍ͯͩ͘͠͞ɻ όϦσʔγϣϯΛࣦഊͤ͞Δ ValidationΛ࣮૷͠Α͏ 222 Selected Method put/patch Uri /api/comments/ {id}

    Parameters name: ࣗ෼ content: ʢۭʣ ֬ೝ 422 The content field is required.
  223. ValidationΛ࣮૷͠Α͏ ֬ೝ 223

  224. 17:30 ·Ͱ֤ࣗͰ࡞ۀΛ͠·͠ΐ͏ɻ Θ͔Βͳ͍͜ͱ͕͋ͬͨΒɺԕྀͳ͘zoomͷνϟοτʹʲ࣭໰ʳΛ͚ͭͯίϝϯτ͍ͯͩ͘͠͞ɻ ͦΕҎ֎ͷίϝϯτ΋େৎ෉Ͱ͢! ΍Δ͜ͱ ɾίϝϯτΛۭʹͨ͠ϦΫΤετ͕ࣦഊ͢Δ͜ ͱΛ֬ೝ͢Δ ɾόϦσʔγϣϯͷॲཧΛ௥Ճ͢Δ ɾจࣈ਺ͷόϦσʔγϣϯʹҾ͔͔ͬΔϦΫΤ ετΛૹΔ

    ֬ೝ ɾεςʔλε422ͰΤϥʔʹͳͬͨΒOKʂ ࡞ۀλΠϜ ValidationΛ࣮૷͠Α͏ ࡞ۀ 224
  225. 2೔໨ऴྃʙʂ WebΞϓϦϑϨʔϜϫʔΫೖ໳ REST API ೖ໳ ݚम͸ऴྃͰ͢ʂ͓ർΕ༷Ͱͨ͠ʂ

  226. τϥϒϧγϡʔςΟϯά 226

  227. ϋϯζΦϯͰ઀ଓͰ͖ͳ͍ํ͕͍ͨͷͰɺ໰୊੾Γ෼͚ͯ͠௅Έ·͠ΐ͏ɻ - Ͱ͖ΔʢVSCodeͷηοτΞοϓͷ໰୊͔΋ʣ - Remote-SSHΛҰ୴ΞϯΠϯετʔϧɾΠϯετʔϧ͠Α͏ - VSCodeΛҰ୴ΞϯΠϯετʔϧɾΠϯετʔϧ͠Α͏ - Ͱ͖ͳ͍ʢConoHaͷηοτΞοϓͷ໰୊͔΋ʣ -

    ެ։伴Λαʔόʔʹొ࿥͠Α͏ - ൿີ伴ΛվΊͯChromeͰμ΢ϯϩʔυ͠Α͏ʢݪҼ֬཰͸௿ʣ ֬ೝ : CUIͰConoHaʹssh઀ଓͰ͖·͔͢ʁ Remote-SSHͰConoHaʹ઀ଓͰ͖ͳ͍ 227
  228. .ssh/config ͷઃఆ͸օͰ͖·ͨ͠Ͷɻ Macͷํ͸TerminalɺWindowsͷํ͸Git BashͰsshͰ͖Δ͔֬ೝ͠·͠ΐ͏ɻ ֬ೝ : CUIͰConoHaʹssh઀ଓͰ͖·͔͢ʁ Remote-SSHͰConoHaʹ઀ଓͰ͖ͳ͍ 228 ࡞ۀ

    # ࣮ߦ͢ΔίϚϯυ (.ssh/config ʹొ࿥ͨ͠ Hostname ͕ Conoha ͷ৔߹) ssh Conoha ਖ਼ৗ࣌ͷը໘
  229. ίϚϯυΛ࣮ߦͯ͠ެ։伴Λొ࿥͠·͢ɻࣄલʹҎԼͷ3ͭΛ֬ೝ͠·͠ΐ͏ɻ - ൿີ伴ͷPath (.ssh/config ʹॻ͍ͯ͋ΔΑ) - ConoHaͷIP (.ssh/config ʹॻ͍ͯ͋ΔΑ) -

    ConoHaͷrootύεϫʔυ ެ։伴Λαʔόʔʹొ࿥͠Α͏ Remote-SSHͰConoHaʹ઀ଓͰ͖ͳ͍ 229 ࡞ۀ # ൿີ伴͕ར༻Ͱ͖ɺެ։伴Λੜ੒Ͱ͖Δ͔֬ೝ͢ΔίϚϯυ ssh-keygen -y -f <ൿີ伴ͷPath>
  230. ެ։伴Λੜ੒Ͱ͖Δ͜ͱΛ֬ೝͨ͠ΒConoHaʹొ࿥͠·͠ΐ͏ɻ ެ։伴Λαʔόʔʹొ࿥͠Α͏ Remote-SSHͰConoHaʹ઀ଓͰ͖ͳ͍ 230 ࡞ۀ # ࣮ߦ͢ΔίϚϯυ ssh-keygen -y -f

    <ൿີ伴ͷPath> | ssh root@<ConoHaͷIP> 'cat >> .ssh/authorized_keys' # ࣮ߦͨ͠ΒrootύεϫʔυΛฉ͔ΕΔͷͰೖྗͯ͠EnterΩʔΛԡ͢ # ໰୊ͳͦ͞͏Ͱ͋Ε͹ɺ࠶ͼConoHaʹssh઀ଓͯ͠ΈΑ͏