centrex / laravel-model-note
This package add note to eloquent model
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
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Contents
Installation
You can install the package via composer:
composer require centrex/laravel-model-note
You can publish the config file with:
php artisan vendor:publish --tag="laravel-model-note-config"
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-model-note-migrations"
php artisan migrate
Usage
Add the HasNotes
trait to a model you like to use notes on.
use Centrex\LaravelModelNote\HasNotes; class YourEloquentModel extends Model { use HasNotes; }
Add a new note
You can add a new note like this:
$model->addNote('whatever you like');
Add a private note
You can add a new private note which can be seen only be you like this:
$model->addNote('whatever you like' , true); //or alternatively $model->addPrivateNote('whatever you like');
Add a note with tag
Sometimes you will need to tag your note with some tag which can be done like this:
$model->addNote('whatever you like' , false , "tag1"); //or for the private note $model->addPrivateNote('whatever you like' , "tag2");
Retrieving notes
You can get the last note of model:
$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 associated notes of a model can be retrieved like this:
$all_notes = $model->notes; //or alternatively $all_notes = $model->notes();
All associated notes of a model with specific tag or tags can be retrieved like this:
//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");
All associated private notes of a model with specific tag or tags can be retrieved like this:
//specific tag $all_notes = $model->privateNotes("tag1"); //specific tags $all_notes = $model->privateNotes("tag1" , "tag2");
Delete a note from model
You can delete any note that has been added on the model by id at any time by using the deleteNote
method:
//specific id $model->deleteNote(1); //specific ides $model->deleteNote(1, 2, 3);
You can delete any note that has been added on the model by tag at any time by using the deleteNote
method:
//specific tag $model->deleteNoteByTag("tag1"); //specific tags $model->deleteNoteByTag("tag1", "tag2", "tag3");
Delete all notes from model
You can delete all notes that had been added on the model at any time by using the deleteAllNotes
method:
Delete all notes from model:
$model->deleteAllNotes();
Testing
๐งน Keep a modern codebase with Pint:
composer lint
โ Run refactors using Rector
composer refacto
โ๏ธ Run static analysis using PHPStan:
composer test:types
โ Run unit tests using PEST
composer test:unit
๐ Run the entire test suite:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.