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

Laravel Activity Logを使って簡単に変更履歴機能を実装しよう

Takayuki
January 15, 2022

Laravel Activity Logを使って簡単に変更履歴機能を実装しよう

変更履歴の機能を実装するのって、考慮する事も多いし、大変ですよね?
Laravel Activity Logを使うと、簡単に変更履歴の機能を実装できます。

Takayuki

January 15, 2022
Tweet

More Decks by Takayuki

Other Decks in Programming

Transcript

  1. 鈴木孝之 Laravel Activity LogΛ࢖ͬͯ؆୯ ʹมߋཤྺػೳΛ࣮૷͠Α͏

  2. "HFOEB ࣗݾ঺հɾձࣾ঺հ มߋཤྺػೳ։ൃͷ՝୊ ΍Γ͍ͨࣄ ࣮૷ํ๏

  3. Copyright Re:Build.inc All Rights Reserved. ର৅ऀʹ͍ͭͯ 0 -BSBWFMͷجૅ஌͕ࣝ͋Δ ॳڃऀʙதڃऀ޲͚

  4. ࣗݾ঺հɾձࣾ঺հ

  5. Copyright Re:Build.inc All Rights Reserved. ࣗݾ঺հ 0 ◆໊લ ླ໦ ޹೭(Suzuki

    Takayuki) ※ಉ੏ಉ໊ଟͯ͘ࠔͬͯ·͢ɻɻɻ ◆ࣗݾ঺հ ɾ1990೥ੜ·Εɻ ɾΤϯδχΞˠϑϦʔϥϯεˠԭೄͰىۀ ɾPHPΧϯϑΝϨϯεԭೄ࣮ߦҕһ௕ɺ ϑϩϯτΤϯυΧϯϑΝϨϯεԭೄ࣮ߦҕһ௕ ◆झຯ ίεϓϨɺԻָϥΠϒɺϚϥιϯେձʹग़Δɺ໺ٿ؍ઓ BDD(Ϗʔνۦಈ։ൃ)
  6. Copyright Re:Build.inc All Rights Reserved. ࣗݾ঺հ 1

  7. Copyright Re:Build.inc All Rights Reserved. ധ̏೔Ͱ։࠵ʂࣾ֎ͷํ΋ ߹ಉͰ։ൃͯ͠·͢ʂ ϦϏϧυԭೄ։ൃ߹॓ 0

  8. Copyright Re:Build.inc All Rights Reserved. ϦϏϧυԭೄ։ൃ߹॓ 0

  9. Copyright Re:Build.inc All Rights Reserved. ࣗݾ঺հ 0

  10. Copyright Re:Build.inc All Rights Reserved. ձࣾ঺հ 0 ◆ձ໊ࣾ גࣜձࣾRe:Build ◆ॅॴ

    ԭೄݝಹ೼ࢢٱໜ஍2-2-2 λΠϜεϏϧ ◆ࣄۀ಺༰ ɾࣗࣾWEBαʔϏεͷاըɾ։ൃɻ ɾडୗ։ൃ ɾϓϩάϥϛϯάεΫʔϧ ◆ࣾһ 12໊ ΤϯδχΞืूͯ͠·͢ʂʂʂ
  11. มߋཤྺػೳ։ൃͷ՝୊

  12. Copyright Re:Build.inc All Rights Reserved. มߋཤྺػೳ։ൃͷ՝୊ - มߋཤྺͷػೳΛ࣮૷͢Δͷͬͯɺߟྀ͢Δࣄ΋ଟ͍͠ɺେ มͰ͢ΑͶʁ -

    Laravel Activity LogΛ࢖͏ͱɺ؆୯ʹมߋཤྺͷػೳΛ࣮૷ Ͱ͖·͢ɻ 1
  13. Copyright Re:Build.inc All Rights Reserved. 1 มߋཤྺػೳ։ൃͷ՝୊ DBઃܭ͕େม શػೳͷૢ࡞มߋཤྺΛ ࢒͢ͱͳΔͱɺӨڹൣғ

    ͕޿͍ มߋཤྺͷ෮ݩ͕೉͍͠
  14. ΍Γ͍ͨࣄ

  15. Copyright Re:Build.inc All Rights Reserved. ΍Γ͍ͨ͜ͱ - σʔλͷ࡞੒ɾߋ৽ɾ࡟আͷϢʔβ ͷಈ࡞ʹରͯ͠ཤྺΛ࢒͍ͨ͠ɻ -

    มߋཤྺσʔλΛը໘ʹදࣔͨ͠ ͍ɻ - ޙͰཤྺσʔλΛ෮ݩͰ͖ΔΑ͏ʹ ͓͖͍ͯͨ͠ɻ 2
  16. ࣮૷ํ๏

  17. Copyright Re:Build.inc All Rights Reserved. ࢖͏ύοέʔδ 3 https://github.com/spatie/laravel-activitylog ͜ͷspatie/laravel-activitylogύοέʔδ͸ɺ ϢʔβʔͷΞΫςΟϏςΟΛϩάʹه࿥͢Δͨ

    Ίͷ࢖͍΍͍ؔ͢਺Λఏڙ͠·͢ɻϞσϧΠϕ ϯτΛࣗಈతʹϩάʹه࿥͢Δ͜ͱ΋Ͱ͖· ͢ɻ laravel-activitylogͱ͸ʁ
  18. Copyright Re:Build.inc All Rights Reserved. ࢖͏ύοέʔδ 3 https://github.com/spatie/laravel-activitylog - มߋର৅ͷର৅DBΛه࿥

    - มߋ͕͋ͬͨࡍͷઆ໌จΛه࿥ - มߋલͱมߋޙͷσʔλͷࠩ෼Λه࿥ laravel-activitylogͰग़དྷΔࣄ
  19. Copyright Re:Build.inc All Rights Reserved. 1.ύοέʔδͷΠϯετʔϧ 3 ԼهͷίϚϯυΛ࣮ߦ͢Δ $ composer

    require spatie/laravel-activitylog $ php artisan vendor:publish -- provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog- migrations"
  20. Copyright Re:Build.inc All Rights Reserved. 2.ϚΠάϨʔγϣϯͷ࣮ߦ 3 migrateΛ࣮ߦͯ͠activity_logςʔϒϧΛ࡞ ੒͠·͢ɻ $

    php artisan migrate
  21. Copyright Re:Build.inc All Rights Reserved. 3.Modelͷमਖ਼ 3 useͰLogsActivityΛࢦఆ͢ΔͷͱɺgetActivitylogOptions()ͷؔ਺಺ʹมߋཤྺʹ࢒͍ͨ͠ΧϥϜΛࢦఆ͠·͢ɻ

  22. Copyright Re:Build.inc All Rights Reserved. 4.Controllerͷमਖ਼ 3 - activity()Ͱର৅ͷModelࢦఆ͠·͢ɻ -

    causedBy()Ͱߋ৽࡞ۀΛ࣮ߦ͢Δ ϢʔβΛࢦఆ͠·͢ɻ - log()ͰDBͷdescriptionʹೖΔ಺༰Λ ఆٛ͠·͢ɻ
  23. Copyright Re:Build.inc All Rights Reserved. ొ࿥͞ΕΔσʔλͷྫ 3 ͋ͱ͸DBʹొ࿥͞ΕͨσʔλΛऔಘ͠ ͯɺද͍ࣔͤͨ͞ը໘ʹදࣔͤ͞Ε͹ OKͰ͢ʂ

    มߋͨ͠ σʔλ ը໘ʹදࣔ͢ Δཤྺͷจষ
  24. Copyright Re:Build.inc All Rights Reserved. ·ͱΊ - Laravel-activitylogΛ࢖͏ͱɺσʔλͷ࡞੒ɾߋ৽ɾ࡟আͳ ͲͷϢʔβͷಈ࡞ʹରͯ͠ͷཤྺΛ؆୯ʹه࿥Ͱ͖Δʂ
 -

    ͨͩɺಠࣗͷཁ͕݅͋ΔΑ͏ͳ։ൃͩͱɺΧελϚΠζʹ ͸ݶք͕͋Γͦ͏ɻ
  25. Copyright Re:Build.inc All Rights Reserved. ࠂ஌ 2022೥5݄ࠒʹPHPΧϯϑΝϨϯεԭೄΛ։࠵༧ఆͰ͢ʂ ※ίϩφ΢Πϧεͷঢ়گʹΑͬͯ͸ɺมߋʹͳΔՄೳੑ͕͋Γ·͢ɻ