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

Laravelの検索機能の実装方法 Oct. 23, 2022 • 0 likes •

Laravelの検索機能の実装方法 Oct. 23, 2022 • 0 likes •

Laravelにおける検索機能のハンズオンをした際の資料

よしたろう

August 07, 2021
Tweet

More Decks by よしたろう

Other Decks in Programming

Transcript

  1. ❏ର৅ͱͳΔํ • L a r a vel৮Γͨͯͷํ ❏಺༰ • ݕࡧػೳ࣮૷

    • ࣮૷࣌ͷλεΫࡉ෼Խ • ্هʹै͍λεΫͷ࣮ߦ • MVCͷྲྀΕΛ౿·͑ͯ • +αͷิ଍
  2. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  3. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  4. ΫϥΠΞϯτ Laravelʹ͓͚ΔMVCͷྲྀΕͱΠϝʔδ router web.php View Controller ArticleController.php Model Article.php articel.blade.php

    JS CSS img HTTP Ϩεϙϯε ϨϯμϦϯά HTTP ϦΫΤετ URLͰRouting ඞཁͳΒ DBΞΫηε σʔλΛ౉͢ CRUD ॲཧ݁Ռ σʔλΛૹΔ
  5. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  6. ΫϥΠΞϯτ Laravelʹ͓͚ΔMVCͷྲྀΕͱΠϝʔδ router web.php View Controller ArticleController.php Model Article.php articel.blade.php

    JS CSS img HTTP Ϩεϙϯε ϨϯμϦϯά HTTP ϦΫΤετ URLͰRouting ඞཁͳΒ DBΞΫηε σʔλΛ౉͢ CRUD ॲཧ݁Ռ σʔλΛૹΔ
  7. 2. Client ͷ Request Parameter औಘ 1. input λάͷ v

    a lue ଐੑΛઃఆ͢Δ 2. Controller Ͱ RequestP a r a meter Λऔಘ
  8. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3.औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  9. 2. ɾ Eloquent ͷಛ௃ͱϝϦοτ • Eloquent ͸ɺL a r a

    vel ͕ఏڙ͍ͯ͠Δ O/R Ϛού • Eloquent O/R Ϛού͸ ActiveRecord ύλʔϯͰ࣮૷͞Ε͍ͯΔ • SQL ͱ͍͏ผͷݴޠΛɺΞϓϦέʔγϣϯʢ L a r a vel ʣʹհೖͤͣࡁΉ • ςʔϒϧಉ࢜ͷؔ܎ੑΛఆٛͰ͖Δ • ࠶ར༻ੑ΍֦ுੑ͕ߴ͍ ɾ Eloquent ͷσϝϦοτ • SQL ͕ॻ͚ͳͯ͘΋ɺσʔλऔಘ͕Ͱ͖Δ • Ͳ͏͍͏ΫΤϦΛൃߦ͍ͯ͠Δͷ͔Θ͔Βͳ͍ • ಛఆͷϝιουΛ࢖͏ͱɺαϒΫΤϦΛ࢖࣮ͬͯߦ͢Δ ɾ Eloquent ͷ࢖༻৔໘ • ύϑΥʔϚϯεΑΓ΋҆શੑΛऔΓ͍ͨ • ࣮֬ʹɺϦϨʔγϣϯʹԊͬͨσʔλऔಘΛ͍ͨ͠ • ಛఆͷঢ়گԼͰͷ৚݅෇͚΍ɺॲཧͷ࣮ߦΛ࣮૷͍ͨ͠
  10. 2. ɾ QueryBuilder ͷಛ௃ͱϝϦοτ • L a r a vel

    ͕ఏڙ͍ͯ͠ΔΫΤϦΛੜ੒͢ΔͨΊͷϝιου܈ɻ • SQL ϥΠΫʹΫΤϦΛॻ͘͜ͱ͕Ͱ͖Δ • Eloquent ͱൺ΂ͯߴ଎ • ൃߦ͞Ε͍ͯΔΫΤϦ͕ղΓ΍͍͢ • SQL Λॻ͚Ε͹ֶशίετ͸௿͍ ɾ QueryBuilder ͷσϝϦοτ • ࣗྗͰߟྀ͠ͳ͚Ε͹͍͚ͳ͍఺͕͋Δ • ςʔϒϧಉ࢜ͷ݁߹͸Λߦ͏ඞཁ͕͋ΓϦϨʔγϣϯΛਖ਼͘͠೺Ѳ͠൓ө͢Δඞཁ͕͋ Δ • ࿦ཧ࡟আͷ৚݅͸ɺࣗ෼Ͱ৚݅ࢦఆ͢Δ • ͦ΋ͦ΋ SQL จͰؒҧͬͨॻ͖ํΛॻ͍ͯ͸͍͚ͳ͍ ɾ QueryBuilder ͷ࢖༻৔໘ • ෳࡶͳ৚݅΍େྔͷσʔλΛѻ͏ͷͰɺύϑΥʔϚϯεΛٻΊ͍ͨ ʢݕࡧը໘ɺҰཡը໘ͱ͔ʣ • ෳࡶͳ৚݅ͷΫΤϦΛɺൃߦ͍ͨ͠
  11. 2. ɾ Eloquent ͷಛ௃ • Eloquent ͸ɺL a r a

    vel ͕ఏڙ͍ͯ͠Δ O/R Ϛού • SQL ͱ͍͏ผͷݴޠΛɺΞϓϦέʔγϣϯʢ L a r a vel ʣʹհೖͤͣࡁΉ • ςʔϒϧಉ࢜ͷؔ܎ੑΛఆٛͰ͖Δ • ࠶ར༻ੑ΍֦ுੑ͕ߴ͍ ɾ QueryBuilder ͷಛ௃ • L a r a vel ͕ఏڙ͍ͯ͠ΔΫΤϦΛੜ੒͢ΔͨΊͷϝιου܈ɻ • SQL ϥΠΫʹΫΤϦΛॻ͘͜ͱ͕Ͱ͖Δ • Eloquent ͱൺ΂ͯߴ଎ • ൃߦ͞Ε͍ͯΔΫΤϦ͕ղΓ΍͍͢ • SQL Λॻ͚Ε͹ֶशίετ͸௿͍
  12. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  13. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  14. ΫϥΠΞϯτ 2. 3૚ΞʔΩςΫνϟͱLeravelͰͷMVCͷؔ܎ Webαʔό ΞϓϦέʔγϣϯαʔό DBαʔό ※ड෇ ※۩ମతͳॲཧ ※σʔλϕʔε HTTP

    HTTP ϓϨθϯςʔγϣϯ૚ ϏδωεϩδοΫ૚ σʔλΞΫηε૚ Ϣʔβʔͱͷ ΍ΓऔΓ ɾϖʔδͷಡΈऔΓ ɾೖྗͷड෇ ϓϩάϥϜͰ ॲཧΛߦ͏ ɾϧʔϧΛ΋ͭ DBΛૢ࡞͠ ݁ՌΛอଘ͢Δ ɾॻ͔ͳ͍ࣄ΋͋Δ View Controller Model CRUD ॲཧ݁Ռ
  15. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ
  16. 6. Request Parameter Λ Cast ͢Δ 1. GET/POST Ͱͷ RequestP

    a r a meter ͸ೖྗ஋νΣοΫ 2. ܕม׵(C a st) ɺRequestP a r a meter ͸શ෦ String Β͍͠
  17. https://www.php.net/m a nu a l/j a / l a ngu

    a ge.types.type- juggling.php#l a ngu a ge.types.typec a sting PHP ϚχϡΞϧ>ݴޠϦϑΝϨϯε >ܕ>ܕͷ૬ޓม׵ ΑΓҾ༻
  18. https://www.php.net/m a nu a l/j a / l a ngu

    a ge.types.decl a r a tions.php ʮPHP ϚχϡΞϧ>ݴޠϦϑΝϨϯε>ܕ>ܕએݴ ʯ ΑΓҾ༻
  19. ɾLaravelͷݕࡧػೳͷ࣮૷ํ๏ 1. Routingઃఆ 2. Client ͷ Request P a r

    a meter औಘ 3. औಘͨ͠ P a r a meter Ͱ Query Λ࡞੒ 4. Query Ͱ৘ใΛऔಘ͠Viewʹ౉͢ 5. ݕࡧ method Λ Model ʹ੾Γ෼͚Δ 6. Request P a r a meter Λ C a st ͢Δ 7. ·ͱΊ MVCϞσϧͷ f lowʹԊͬͯ