Last active
February 18, 2024 13:23
-
-
Save caingougou/58eab03d2dee6c4a14724ec3baf95c46 to your computer and use it in GitHub Desktop.
只有在 updating 和 updated 中 decrement 和 increment 才会触发
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
<?php | |
class Product extends Model { | |
public static function boot() { | |
parent::boot(); | |
static::updating(function ($model) { | |
// 只有在 updating 和 updated 中 decrement 和 increment 才会触发 | |
}); | |
} | |
} | |
Product::find(1)->decrement('stock'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
laravel/framework#32567 (comment)