centrex / laravel-model-note
此包为eloquent模型添加注释
v1.0.4
2024-09-17 11:39 UTC
Requires
- php: ^8.1|^8.2
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- larastan/larastan: ^2.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.30
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- rector/rector: ^1.1
- spatie/laravel-ray: ^1.26
README
这里应该是你的描述。尽量限制在一两段话内。考虑添加一个小的示例。
内容
安装
您可以通过composer安装此包
composer require centrex/laravel-model-note
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-model-note-config"
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="laravel-model-note-migrations"
php artisan migrate
使用
将 HasNotes
特性添加到您希望使用注释的模型中。
use Centrex\LaravelModelNote\HasNotes; class YourEloquentModel extends Model { use HasNotes; }
添加新注释
您可以通过以下方式添加新注释
$model->addNote('whatever you like');
添加私有注释
您可以通过以下方式添加新的私有注释,这样只有您可以看到
$model->addNote('whatever you like' , true); //or alternatively $model->addPrivateNote('whatever you like');
添加带标签的注释
有时您需要将一些标签添加到注释中,可以这样做
$model->addNote('whatever you like' , false , "tag1"); //or for the private note $model->addPrivateNote('whatever you like' , "tag2");
获取注释
您可以获取模型的最后一条注释
$model->note; // returns the text of the last note $model->note(); // returns the last instance of `Centrex\LaravelModelNote\ModelNote` //or alternatively $model->lastNote(); // returns the last instance of `Centrex\LaravelModelNote\ModelNote`
可以通过以下方式检索模型的全部相关注释
$all_notes = $model->notes; //or alternatively $all_notes = $model->notes();
可以通过以下方式检索具有特定标签或多个标签的模型的全部相关注释
//last note of specific tag $last_note = $model->lastNote("tag1"); //specific tag $all_notes = $model->allNotes("tag1"); //specific tags $all_notes = $model->allNotes("tag1" , "tag2");
可以通过以下方式检索具有特定标签或多个标签的模型的全部相关私有注释
//specific tag $all_notes = $model->privateNotes("tag1"); //specific tags $all_notes = $model->privateNotes("tag1" , "tag2");
从模型中删除注释
您可以通过id在任何时候使用 deleteNote
方法删除模型上已添加的任何注释
//specific id $model->deleteNote(1); //specific ides $model->deleteNote(1, 2, 3);
您可以通过tag在任何时候使用 deleteNote
方法删除模型上已添加的任何注释
//specific tag $model->deleteNoteByTag("tag1"); //specific tags $model->deleteNoteByTag("tag1", "tag2", "tag3");
从模型中删除所有注释
您可以通过 deleteAllNotes
方法在任何时候删除模型上已添加的所有注释
从模型中删除所有注释
$model->deleteAllNotes();
测试
🧹 使用 Pint 保持现代代码库
composer lint
✅ 使用 Rector 运行重构
composer refacto
⚗️ 使用 PHPStan 运行静态分析
composer test:types
✅ 使用 PEST 运行单元测试
composer test:unit
🚀 运行整个测试套件
composer test
变更日志
有关最近更改的更多信息,请参阅 变更日志
贡献
有关详细信息,请参阅 贡献指南
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅 许可文件