Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Laravel 初めての業務で遭遇したハマりポイント×2
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
takf
May 22, 2019
Technology
3.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Laravel 初めての業務で遭遇したハマりポイント×2
takf
May 22, 2019
More Decks by takf
See All by takf
Go未経験・MVC脳のエンジニアが オニオンアーキテクチャを学ぶまで
takfjp
0
49
見やすい PRを作るために取り組んでいること
takfjp
0
78
Denoに入門していきなりAleph.jsを触ってみた
takfjp
0
550
Atomic Design とテストの○○な話
takfjp
2
2k
Node.jsのアップグレードで気をつけたこと
takfjp
1
3k
FARM スタックに触れてみる
takfjp
0
1.7k
React Testing Library の Query について整理してみた
takfjp
0
580
React.js 消えるライフサイクルメソッドについて
takfjp
0
170
React で Stateless Functional Component の書き方を盛大に間違えていた話
takfjp
0
470
Other Decks in Technology
See All in Technology
Devin プロモコードの受け取りと適用(2026.10.27)
kinopeee
1
760
あなたのDartコードは丸見えかもしれない ~reFlutterで暴くFlutterアプリの中身と多層防御~
zozotech
PRO
0
710
LLMの知識とAIエージェント
happysamurai294
0
130
Vibe-to-Spec開発_実践ガイド
happysamurai294
0
130
Microsoft のサポート ライフサイクルを理解する
murachiakira
PRO
0
240
Claude for Google Workspaces ポン出し/claude-for-google-workspace-slide-conversion
emiki
0
13k
Don't write the architecture only in the prompt.
neohsu
0
270
Agent × Maestro で始める モバイル E2E 端末準備からテスト実行・結果確認まで
sansantech
PRO
0
240
AI時代、つくる力を自分たちの手に。 ──電通×KAG、アジャイルとAI駆動開発で挑む開発の変革
yuukiyo
3
440
推論基盤と Scale-Up Interconnect の現状と制約から俯瞰する技術動向
markunet
2
670
自律的なチームを作るためにTechPMがやらないこと
ny7760
0
270
データマネジメント × 法務で作りあげる、 freeeの新しいデータガバナンスへの軌跡
freee
PRO
2
580
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
エンジニアに許された特別な時間の終わり
watany
109
250k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
490
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
550
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
730
We Have a Design System, Now What?
morganepeng
55
8.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
780
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
380
Transcript
Laravel 初めての業務で遭遇したハマりポイント×2 Takeru Furuichi (Twitter:@takfjp) LaraVue勉強会 2019.05.22
Laravel を初めて業務で使った時にハマったことを 話します ・Eloquent ORM 既存案件の参入時に起こったこと ・論理削除 新規案件の開発時に起こったこと
Model class Something extends Model { protected $table = 'something';
protected $fillable = [ ‘name’ ]; public $timestamps = false; }
Controller public function store(Request $request) { $something = new Something();
$something->name = $request->name; $something->save(); } Form とかからの送信で受け付けたデータを新規保存
レコードが追加されない! save の戻り値は true だった レコードが新規にできるはずが…
Why?
https://readouble.com/laravel/5.8/ja/eloquent.html 主キー Eloquent は更にテーブルの主キーが id というカラム名であると 想定しています。この規約をオーバーライドする場合は、 protected の primaryKey
プロパティを定義してください。
テーブルの中身は 主キーが大文字の ID だった!
Model class Something extends Model { protected $table = 'something';
//明示的に追加 protected $primaryKey = 'ID'; public $timestamps = false; }
Eloquent を活用するなら主キーは なるべく「 id 」に統一しましょう
論理削除 ・Company と Employee のように親子関係にあるテーブル / Modelを作成 ・employee テーブルに company_id
という外部キーを設定 ・Company↔Employee の関係は1対多 ・Company モデルでトレイトを使う use SoftDelets;
マイグレーションファイル up() メソッド内 //子テーブルに対象レコードがある場合、親テーブルのレコード削除を禁止 ->onDelete('restrict'); //親テーブルのレコード更新は許可 ->onUpdate('cascade'); Schema::table('employee', function (Blueprint
$table) { $table->integer('company_id')->unsigned(); $table->foreign('company_id')->references('id')->on('companies') ->onDelete('restrict') ->onUpdate('cascade'); });
employee を持つ Company で Company::destroy 制約で Company レコードの削除を防げるはず・・・ →普通に Company
が削除できてしまった!
Why?
use SoftDeleteで論理削除をさせている場合 物理削除と違ってdeleted_atにタイムスタンプを書き込む だけ -> 制約をすり抜けてしまう -> onDelete()はトリガーされない
Laravel Soft Cascade https://laravel-news.com/cascading-soft-deletes
Thank you!