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
AIで生成したものをAIでチェックしてる話
ippey
0
1.9k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
620
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
0
6.2k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.2k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.2k
それぞれの特徴から考えるフレームワーク選び
ippey
1
850
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
はじめてのCI - 実践編 -
ippey
1
270
Other Decks in Programming
See All in Programming
Subclassing, Composition, Python, and You
hynek
3
190
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
0
220
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.1k
cgroup v2 support in Kubeadm
kentatada
0
210
VS Code extension: ドラッグ&ドロップでファイルを並び替える
ttrace
0
190
ML-прайсинг_на_Lamoda__вошли_и_вышли__приключение_на_20_минут__Слава_Цыганков.pdf
lamodatech
0
380
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
230
フロントエンドの現在地とこれから
koba04
10
4.6k
Vue :: Better Testing 2024
up1
1
420
CSC509 Lecture 05
javiergs
PRO
0
180
MLOps in Mercari Group’s Trust and Safety ML Team
cjhj
1
130
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
1
310
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
31
1.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
7.6k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
GraphQLの誤解/rethinking-graphql
sonatard
65
9.9k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Building an army of robots
kneath
302
42k
YesSQL, Process and Tooling at Scale
rocio
167
14k
GraphQLとの向き合い方2022年版
quramy
43
13k
The Cost Of JavaScript in 2023
addyosmani
43
5.9k
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݄͘Β͍ʹ։࠵༧ఆ
͋Γ͕ͱ͏͍͟͝·ͨ͠