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