PHP code example of fahedaljghine / laravel-model-note

1. Go to this page and download the library: Download fahedaljghine/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/ */

    

fahedaljghine / laravel-model-note example snippets


// 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


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',

];

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

//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();
bash
php artisan vendor:publish --provider="Fahedaljghine\ModelNote\ModelNoteServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Fahedaljghine\ModelNote\ModelNoteServiceProvider" --tag="config"