centrex/laravel-model-note

This package add note to eloquent model

v1.0.4 2024-09-17 11:39 UTC

This package is auto-updated.

Last update: 2024-11-20 14:07:53 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.