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.2k
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
600
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
0
6k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.2k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.6k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.1k
それぞれの特徴から考えるフレームワーク選び
ippey
1
820
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.7k
はじめてのCI - 実践編 -
ippey
1
260
Other Decks in Programming
See All in Programming
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
530
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
160
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
260
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
400
Debugging: All you need to know (for simultaneous interpreting)
jmatsu
2
700
Lessons by WebAssembly app in production on CDN Edge Computing Service
tetsuharuohzeki
0
200
Modular Monolith Go Server with GraphQL Federation + gRPC
110y
1
580
LangGraphでのHuman-in-the-Loopの実装
os1ma
3
1.1k
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
190
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
2
110
マルチモジュールにおけるテスト最適化
fxwx23
0
200
How to Break into Reading Open Source
kaspth
1
210
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
Unsuck your backbone
ammeep
667
57k
Building Flexible Design Systems
yeseniaperezcruz
325
37k
Building Adaptive Systems
keathley
36
2.1k
In The Pink: A Labor of Love
frogandcode
139
22k
Fontdeck: Realign not Redesign
paulrobertlloyd
80
5.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Producing Creativity
orderedlist
PRO
340
39k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
89
16k
KATA
mclloyd
27
13k
Bootstrapping a Software Product
garrettdimon
PRO
304
110k
Art, The Web, and Tiny UX
lynnandtonic
294
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݄͘Β͍ʹ։࠵༧ఆ
͋Γ͕ͱ͏͍͟͝·ͨ͠