Skip to content

Instantly share code, notes, and snippets.

$post = Post::find(1);
$post->comments()->saveMany([
new Comment(['message' => 'First comment']),
new Comment(['message' => 'Second comment']),
]);
//view_countを一つカウントダウンする
Post::find($post_id)->decreament('view_count');
//ポイントを50減算する
User::find($user_id)->decreament('points', 50);
//view_countを一つカウントアップする
Post::find($post_id)->increment('view_count');
//ポイントを50加算する
User::find($user_id)->increment('points', 50);
//もっとも最近に更新されたレコード
$lastUpdatedUser = User::newest('updated_at')->first();
//降順
User::newest()->get();
//昇順
User::oldest()->get();
//降順
User::orderBy('created_at', 'desc')->get();
//昇順
User::orderBy('created_at', 'asc')->get();
bin/cake migrations status
Status Migration ID Migration Name
up 20211113120214 CreateHoge0
up 20211113121301 CreateHoge1
up 20211113121453 CreateHoge2
bin/cake migrations rollback -t 20211113121453
bin/cake migrations rollback
bin/cake migrations migrate -t 20211113121301
bin/cake migrations status
Status Migration ID Migration Name
up 20211113120214 CreateHoge0
up 20211113121301 CreateHoge1
up 20211113121453 CreateHoge2