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でのDB操作を監視する
Search
Ippei Sumida
May 16, 2020
Programming
2
1.3k
LaravelでのDB操作を監視する
2020-05-16に開催された【オンライン】関西PHP勉強会で発表したスライドです。 #phpkansai
Ippei Sumida
May 16, 2020
Tweet
Share
More Decks by Ippei Sumida
See All by Ippei Sumida
DROBEの生成AI活用事例 with AWS
ippey
0
130
みんなでQAしてる話
ippey
0
79
AIで生成したものをAIでチェックしてる話
ippey
0
2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
770
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.8k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.8k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.5k
それぞれの特徴から考えるフレームワーク選び
ippey
1
910
Other Decks in Programming
See All in Programming
昭和の職場からアジャイルの世界へ
kumagoro95
1
390
ソフトウェアエンジニアの成長
masuda220
PRO
12
2k
sappoRo.R #12 初心者セッション
kosugitti
0
260
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
51
17k
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
170
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
230
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
160
時計仕掛けのCompose
mkeeda
1
300
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
380
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
5
390
Unity Android XR入門
sakutama_11
0
160
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
570
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
A Philosophy of Restraint
colly
203
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Transcript
LaravelͰͷDBૢ࡞Λ ࢹ͢Δ ʲΦϯϥΠϯʳؔPHPษڧձ 2020-05-16 Ippei Sumida
# WHOAMI - ֯ాɹҰฏʢ͢Έͩɹ͍͍ͬʣ - ϑϦʔϥϯεσϕϩούʔ - PHPͳͲͰWeb։ൃͯ͠·͢ - ຕํࢢͷίϫʔΩϯάεϖʔε
ʰSHINCRUʱͷӡӦελοϑͯ͠·͢ - CoderDojoຕํͬͯ·͢
ʮԿͯ͠ͳ͍ͷʹյΕͨʯ
͋ɺσʔλআ͞Εͯ·͢Ͷʔ ˎˎͷσʔλ͕දࣔ͞Εͯͳ͍ΜͰ͚͢Ͳʁ ͑ʂͳʹͯ͠ͳ͍Ͱ͢ΑʂʂόάͰ͔͢ʁʁʁ ͍ɺγεςϜతʹਖ਼ৗʹಈT ͪΌΜͱௐࠪͯ͠ใࠂॻग़͍ͯͩ͘͠͞ʂʂ
͏ͪͷ#͞Μ͕আͨ͠Μͩͬͯ❤
୭͕ԿΛ͔ͨ͠ࢹ͍ͨ͠
Laravel Auditing
Laravel AuditingͰͰ͖Δ͜ͱ Laravel্ͷ… • DBૢ࡞ͷࢹ • ࢹσʔλͷऔಘ • ͩΕ͕ɾ͍ͭɾͲ͜ͰɾͳʹΛ͔ͨ͠ΛѲ •
ߋ৽ͷࠩʢͳʹΛͲ͏ม͔͑ͨʣΛѲ
Πϯετʔϧ composer require owen-it/laravel-auditing
ઃఆ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 <?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
ࢹελʔτ
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
ϓϩάϥϜͰ औಘ <?php $item = Item::find(1); // ֘σʔλͷશͯͷࢹσʔλ $audits =
$item->audits; // ֘σʔλͷ࠷ॳͷࢹσʔλ $first = $item->audits()->first(); // ֘σʔλͷۙͷࢹσʔλ $latest = $item->audits()->latest()->first(); // ֘σʔλͷࢹσʔλͷIDࢦఆ $audit = $item->audits()->find(1);
ͩΕ͕ ԿΛͨ͠ ͞ΘͬͨϞσϧ ͞Θͬͨσʔλ ͼ;͒ʔ ͋;ͨʔ 1 updated App\Item 2
{"name":"\u8ffd\u52a 01"} {"name":"\u8ffd\u52a 02"}
Ͳ͜Ͱ Ͳͷ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
͋ɺσʔλআ͞Εͯ·͢Ͷʔ ˎˎͷσʔλ͕දࣔ͞Εͯͳ͍ΜͰ͚͢Ͳʁ ͑ʂͳʹͯ͠ͳ͍Ͱ͢ΑʂʂόάͰ͔͢ʁʁʁ #͞Μ͕ ͷ ࣌͝ΖʹεϚϗͰআͯ͠·͢Ͷɻ ͦ͏Ͱ͔͢ɻ#͞Μʹฉ͍ͯΈ·͢ʂ
એ
Symfony Meetup Kansai ͬͯ·͢
Symfony Meetup Kansai͜Μͳͱ͜Ζ • Symfonyʹ͍ͭͯࡶஊ͢ΔձʢݱࡏΦϯϥΠϯ։࠵ʣ • SymfonyͷܦݧΘͣ • SymfonyͰʙͭͬͨ͘ɺʙͬͯػೳ͔ͭͬͯΈͨɺͱ͍͏ࣄྫհ ։ൃख๏ͳͲΛใڞ༗
• ࣍6݄͔7݄͘Β͍ʹ։࠵༧ఆ
͋Γ͕ͱ͏͍͟͝·ͨ͠