This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$post = Post::find(1); | |
$post->comments()->saveMany([ | |
new Comment(['message' => 'First comment']), | |
new Comment(['message' => 'Second comment']), | |
]); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//view_countを一つカウントダウンする | |
Post::find($post_id)->decreament('view_count'); | |
//ポイントを50減算する | |
User::find($user_id)->decreament('points', 50); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//view_countを一つカウントアップする | |
Post::find($post_id)->increment('view_count'); | |
//ポイントを50加算する | |
User::find($user_id)->increment('points', 50); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//もっとも最近に更新されたレコード | |
$lastUpdatedUser = User::newest('updated_at')->first(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//降順 | |
User::newest()->get(); | |
//昇順 | |
User::oldest()->get(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//降順 | |
User::orderBy('created_at', 'desc')->get(); | |
//昇順 | |
User::orderBy('created_at', 'asc')->get(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/cake migrations status | |
Status Migration ID Migration Name | |
up 20211113120214 CreateHoge0 | |
up 20211113121301 CreateHoge1 | |
up 20211113121453 CreateHoge2 | |
bin/cake migrations rollback -t 20211113121453 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/cake migrations rollback | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/cake migrations migrate -t 20211113121301 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/cake migrations status | |
Status Migration ID Migration Name | |
up 20211113120214 CreateHoge0 | |
up 20211113121301 CreateHoge1 | |
up 20211113121453 CreateHoge2 |
NewerOlder