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.4k
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
240
みんなでQAしてる話
ippey
0
130
AIで生成したものをAIでチェックしてる話
ippey
0
2.2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
1k
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
7.3k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.4k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
2k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.9k
それぞれの特徴から考えるフレームワーク選び
ippey
1
1k
Other Decks in Programming
See All in Programming
Blazing Fast UI Development with Compose Hot Reload (Bangladesh KUG, October 2025)
zsmb
1
160
Migration to Signals, Resource API, and NgRx Signal Store
manfredsteyer
PRO
0
120
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
940
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
380
ALL CODE BASE ARE BELONG TO STUDY
uzulla
28
6.7k
Domain-centric? Why Hexagonal, Onion, and Clean Architecture Are Answers to the Wrong Question
olivergierke
3
980
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
300
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
120
Leading Effective Engineering Teams in the AI Era
addyosmani
7
640
CSC305 Lecture 12
javiergs
PRO
0
230
iOSでSVG画像を扱う
kishikawakatsumi
0
170
Claude CodeによるAI駆動開発の実践 〜そこから見えてきたこれからのプログラミング〜
iriikeita
0
360
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.3k
The Invisible Side of Design
smashingmag
302
51k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Documentation Writing (for coders)
carmenintech
75
5.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Being A Developer After 40
akosma
91
590k
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
Building Adaptive Systems
keathley
44
2.8k
A Modern Web Designer's Workflow
chriscoyier
697
190k
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݄͘Β͍ʹ։࠵༧ఆ
͋Γ͕ͱ͏͍͟͝·ͨ͠