- Flexible notes system.
- Easy setup & configuration.
- IDE-friendly and well-documented.
Install the package using Composer:
composer require icodestuff/laravel-notes
Note: This package will automatically register itself for Laravel
>= 5.5.
For earlier versions, manually register the service provider in config/app.php:
'providers' => [
// Other service providers...
Icodestuff\LaravelNotes\LaravelNotesServiceProvider::class,
],
Publish the configuration file:
php artisan vendor:publish --provider="Icodestuff\LaravelNotes\LaravelNotesServiceProvider"
Customize the package by editing config/notes.php:
return [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
'prefix' => null,
],
'authors' => [
'table' => 'users',
'model' => App\User::class,
],
'notes' => [
'table' => 'notes',
'model' => Icodestuff\LaravelNotes\Models\Note::class,
],
];
Use the HasManyNotes trait in your model:
use Icodestuff\LaravelNotes\Traits\HasManyNotes;
class Post extends Model {
use HasManyNotes;
}
Add a note:
$post = App\Post::first();
$note = $post->createNote('This is a note!');
Add a note with an author:
$user = App\User::first();
$note = $post->createNote('Note with author', $user);
Retrieve notes:
$notes = $post->notes;
For managing a single note on a model, use the HasOneNote trait:
use Icodestuff\LaravelNotes\Traits\HasOneNote;
class Post extends Model {
use HasOneNote;
}
Access the note:
$note = $post->note;
Add the AuthoredNotes trait to your User model to retrieve all notes authored by a user:
use Icodestuff\LaravelNotes\Traits\AuthoredNotes;
class User extends Model {
use AuthoredNotes;
}
Retrieve the author's notes:
$user = App\User::first();
$notes = $user->authoredNotes;
To find a note by its ID:
$post = App\Post::first();
$note = $post->findNote(1);
Note: The
findNotemethod is only available in theHasManyNotestrait.
Feel free to submit any issues or pull requests! Please read the contribution guidelines first.
If you discover any security issues, please email arcanedev.maroc@gmail.com instead of using the issue tracker.