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

LaravelでのDB操作を監視する

 LaravelでのDB操作を監視する

2020-05-16に開催された【オンライン】関西PHP勉強会で発表したスライドです。 #phpkansai

Ippei Sumida

May 16, 2020
Tweet

More Decks by Ippei Sumida

Other Decks in Programming

Transcript

  1. ઃఆ1 ‘providers’ => [ + OwenIt\Auditing\AuditingServiceProvider::class ], # config/audit.phpੜ੒ php

    artisan vendor:publish —provider \ ”OwenIt\Auditing\AuditingServiceProvider” \ --tag="config" # ϚΠάϨʔγϣϯʢauditsςʔϒϧCREATEʣੜ੒ php artisan vendor:publish —provider \ “OwenIt\Auditing\AuditingServiceProvider" \ -—tag=“migrations" ˌϚΠάϨʔγϣϯ php artisan migrate DPOpHBQQQIQ
  2. ઃఆ2 <?php namespace App; use Illuminate\Database\Eloquent\Model; + use OwenIt\Auditing\Contracts\Auditable; +

    + class Item extends Model implements Auditable - class Item extends Model { + use \OwenIt\Auditing\Auditable; BQQ*UFNQIQ
  3. id user_ty pe user_id event auditabl e_type auditabl e_id old_val

    ues new_val ues url ip_addr ess user_ag ent tags created _at updated _at 1 App\Use r 1 updated App\Item 2 {"name": "\u8ffd\u 52a01"} {"name": "\u8ffd\u 52a02"} http:// localhost :8000/ items/2 127.0.0. 1 Mozilla/ 5.0 (Macinto sh; Intel Mac OS X 10_15_3 NULL 2020-03- 23 12:20:34 2020-03- 23 12:20:34 2 App\Use r 1 created App\Item 3 [] {"name": "\u307b\ u3052"," stock":"1 0","id":3} http:// localhost :8000/ items 127.0.0. 1 Mozilla/ 5.0 (Macinto sh; Intel Mac OS X 10_15_3 NULL 2020-03- 23 12:21:39 2020-03- 23 12:21:39 3 App\Use r 1 deleted App\Item 3 {"id":"3"," name":"\ u307b\u 3052","st ock":"10" } [] http:// localhost :8000/ items/3 127.0.0. 1 Mozilla/ 5.0 (Macinto sh; Intel Mac OS X 10_15_3 NULL 2020-03- 23 12:51:57 2020-03- 23 12:51:57
  4. ϓϩάϥϜͰ औಘ <?php $item = Item::find(1); // ֘౰σʔλͷશͯͷ؂ࢹσʔλ $audits =

    $item->audits; // ֘౰σʔλͷ࠷ॳͷ؂ࢹσʔλ $first = $item->audits()->first(); // ֘౰σʔλͷ௚ۙͷ؂ࢹσʔλ $latest = $item->audits()->latest()->first(); // ֘౰σʔλͷ؂ࢹσʔλͷIDࢦఆ $audit = $item->audits()->find(1);
  5. Ͳ͜Ͱ ͲͷIPΞυϨεͰ Ͳͷϒϥ΢βͰ ͍ͭ http://localhost:8000/items/2 127.0.0.1 Mozilla/5.0 (Macintosh; Intel Mac

    OS X 10_15_3) AppleWebKit/ 605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15 2020-03-23 12:20:34