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
170
みんなでQAしてる話
ippey
0
93
AIで生成したものをAIでチェックしてる話
ippey
0
2.1k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
850
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
7k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.9k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.6k
それぞれの特徴から考えるフレームワーク選び
ippey
1
960
Other Decks in Programming
See All in Programming
SQL Server ベクトル検索
odashinsuke
0
170
The Implementations of Advanced LR Parser Algorithm
junk0612
1
270
これだけは知っておきたいクラス設計の基礎知識 version 2
masuda220
PRO
24
6.3k
タイムゾーンの奥地は思ったよりも闇深いかもしれない
suguruooki
1
630
The Weight of Data: Rethinking Cloud-Native Systems for the Age of AI
hollycummins
0
270
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
130
音声プラットフォームのアーキテクチャ変遷から学ぶ、クラウドネイティブなバッチ処理 (20250422_CNDS2025_Batch_Architecture)
thousanda
0
130
Defying Front-End Inertia: Inertia.js on Rails
skryukov
0
480
リアルタイムレイトレーシング + ニューラルレンダリング簡単紹介 / Real-Time Ray Tracing & Neural Rendering: A Quick Introduction (2025)
shocker_0x15
1
300
Exit 8 for SwiftUI
ojun9
0
130
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
6
990
フロントエンドテストの育て方
quramy
11
3k
Featured
See All Featured
Building Adaptive Systems
keathley
41
2.5k
Optimising Largest Contentful Paint
csswizardry
36
3.2k
4 Signs Your Business is Dying
shpigford
183
22k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
Documentation Writing (for coders)
carmenintech
69
4.7k
Git: the NoSQL Database
bkeepers
PRO
430
65k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Building Flexible Design Systems
yeseniaperezcruz
329
38k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
What's in a price? How to price your products and services
michaelherold
245
12k
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݄͘Β͍ʹ։࠵༧ఆ
͋Γ͕ͱ͏͍͟͝·ͨ͠