icodestuff/laravel-notes

Provides the ability to add notes to your Eloquent models in Laravel.

1.0.2 2024-11-16 04:01 UTC

This package is auto-updated.

Last update: 2024-11-16 04:02:39 UTC


README

Logo Laravel Pint

Packagist License Github Workflow Status Coverage Status Packagist Downloads

Laravel Notes is a flexible and easy-to-use package that adds a notes system to your Laravel application. It’s well-tested, highly configurable, and works seamlessly with multiple Laravel versions.

Features

  • Flexible notes system.
  • Easy setup & configuration.
  • IDE-friendly and well-documented.

Table of Contents

  1. Installation and Setup
  2. Configuration
  3. Usage
  4. Contribution Guidelines
  5. Security
  6. Credits

1. Installation and Setup

Installation via Composer

Install the package using Composer:

composer require icodestuff/laravel-notes

Setup for Laravel

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"

2. Configuration

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,
    ],
];

3. Usage

Adding Notes to Models

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;

Using the HasOneNote Trait

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;

Retrieve Author's Notes

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;

Find a Specific Note by ID

To find a note by its ID:

$post = App\Post::first();
$note = $post->findNote(1);

Note: The findNote method is only available in the HasManyNotes trait.

Contribution

Feel free to submit any issues or pull requests! Please read the contribution guidelines first.

Security

If you discover any security issues, please email arcanedev.maroc@gmail.com instead of using the issue tracker.

Credits