PHP code example of centrex / laravel-model-note

1. Go to this page and download the library: Download centrex/laravel-model-note library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

centrex / laravel-model-note example snippets


use Centrex\LaravelModelNote\HasNotes;

class YourEloquentModel extends Model
{
    use HasNotes;
}

// Add a public note
$model->addNote('whatever you like');
// or with tag
$user->addNote('Customer called about billing issue', false, 'support');

$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");

// Get all private notes
$privateNotes = ModelNote::private()->get();

// Get public notes with specific tag
$publicTaggedNotes = ModelNote::public()->withTag('feedback')->get();

// Get time ago for a note
$note = ModelNote::first();
echo $note->time_ago; // "2 hours ago"

//specific id
$model->deleteNote(1);

//specific ides
$model->deleteNote(1, 2, 3);


//specific tag
$model->deleteNoteByTag("tag1");

//specific tags
$model->deleteNoteByTag("tag1", "tag2", "tag3");


$model->deleteAllNotes();

try {
    // Validate model class
    if (!is_subclass_of($modelClass, ModelNote::class)) {
        throw InvalidNoteModel::create($modelClass);
    }
} catch (InvalidNoteModel $e) {
    // Access additional context
    $context = $e->context();
    
    // Log full error details
    logger()->error($e->getMessage(), $context);
    
    // Handle exception appropriately
}
bash
php artisan vendor:publish --tag="laravel-model-note-config"
bash
php artisan vendor:publish --tag="laravel-model-note-migrations"
php artisan migrate