Skip to content

Instantly share code, notes, and snippets.

@caingougou
Last active February 18, 2024 13:23
Show Gist options
  • Save caingougou/58eab03d2dee6c4a14724ec3baf95c46 to your computer and use it in GitHub Desktop.
Save caingougou/58eab03d2dee6c4a14724ec3baf95c46 to your computer and use it in GitHub Desktop.
只有在 updating 和 updated 中 decrement 和 increment 才会触发
<?php
class Product extends Model {
public static function boot() {
parent::boot();
static::updating(function ($model) {
// 只有在 updating 和 updated 中 decrement 和 increment 才会触发
});
}
}
Product::find(1)->decrement('stock');
@caingougou
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment