fahedaljghine / laravel-model-note
一个为Eloquent模型添加备注的包
1.0.2
2022-06-24 15:51 UTC
Requires
- php: ^8.0
- illuminate/support: ^8.71|^9.0
Requires (Dev)
- orchestra/testbench: ^6.23|^7.0
- phpunit/phpunit: ^9.4
README
此包提供了一个HasNotes
特性,一旦安装到模型中,就可以执行如下操作:
// add a note $model->addNote('needs manager approve'); // add another note $model->addNote('manager approved'); // get the current status $model->notes(); // returns a collection of \Fahedaljghine\ModelNotes\Note // get the last note $lastNote = $model->lastNote(); // returns an instance of \Fahedaljghine\ModelNotes\Note
联系我
您可以通过检查我的网站来查看我的所有信息。
安装
您可以通过composer安装此包
composer require fahedaljghine/laravel-model-note
您必须使用以下命令发布迁移
php artisan vendor:publish --provider="Fahedaljghine\ModelNote\ModelNoteServiceProvider" --tag="migrations"
迁移notes
表
php artisan migrate
可选地,您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Fahedaljghine\ModelNote\ModelNoteServiceProvider" --tag="config"
此文件的内容将被发布到config/model-note.php
return [ /* * The class name of the notes model that holds all notes. * * The model must be or extend `Fahedaljghine\ModelNote\Note`. */ 'note_model' => Fahedaljghine\ModelNote\Note::class, /* * The name of the column which holds the ID of the model related to the notes. * * You can change this value if you have set a different name in the migration for the notes table. */ 'model_primary_key_attribute' => 'model_id', ];
用法
将HasNotes
特性添加到您想要添加备注的模型中。
use Fahedaljghine\ModelNote\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 `Fahedaljghine\ModelNote\Note` //or alternatively $model->lastNote(); // returns the last instance of `Fahedaljghine\ModelNote\Note`
可以通过这种方式检索模型的所有相关备注
$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");
从模型中删除备注
您可以使用deleteNote
方法在任何时候通过id删除模型中添加的任何备注
//specific id $model->deleteNote(1); //specific ides $model->deleteNote(1, 2, 3);
您可以使用deleteNote
方法在任何时候通过标签删除模型中添加的任何备注
//specific tag $model->deleteNoteByTag("tag1"); //specific tags $model->deleteNoteByTag("tag1", "tag2", "tag3");
从模型中删除所有备注
您可以使用deleteAllNotes
方法在任何时候删除模型中添加的所有备注
从模型中删除所有备注
$model->deleteAllNotes();
自定义模型和迁移
您可以通过在model-note
配置文件的note_model
键中指定类名来更改使用的模型。
当您使用自定义迁移更改默认的model_id
列名时,可以更改备注表中使用的列名。在这种情况下,只需更改model-note
配置文件中的model_primary_key_attribute
键。
变更日志
请参阅CHANGELOG获取有关最近更改的更多信息。
Dontae
贡献
欢迎您贡献
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。