2017 © Pedro Peláez
 

library laravel-notes

Notes for Laravel 5 Models

image

dcastanera/laravel-notes

Notes for Laravel 5 Models

  • Wednesday, February 28, 2018
  • by dcastanera
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel Notes

This Laravel package is a simple morphable object for attaching notes to any object class in your system., (*1)

Installation

To install this package you must use composer. Enter the following:, (*2)

composer require dcastanera/laravel-notes

Service Provider

Next we want to register the service provider in the /config/app.php file. Go to the array for providers and enter the following:, (*3)

DCastanera\Roles\RolesServiceProvider::class,

Migrations

Next we need to copy the migrations to add the notes table to the database:, (*4)

php artisan vendor:publish

Next we need to run the migration., (*5)

php artisan migrate

Usage

In order to use the notes model you need to reference the package like so:, (*6)

use DCastanera\Notes\Note;

Add to Model

In order for you to access notes we need to add the notes method to the desired object you wish to attach notes to. You can do that by adding the following function to your object., (*7)

public function notes()
{
    return $this->morphMany('DCastanera\Notes\Note', 'noteable');
}

Creating a note

In order to create a note you need to first create the note and attach it to the object in order to save the relationship., (*8)

$note = new Note;
$note->note = 'This is the actual note content.';
$note->user_id = $user->id;

$object = new SomeObject;
$object->notes()->save($note);

Deleting a note

To delete a note, you can simply call the note object by ID and delete:, (*9)

$note = Note::find(1);
$note->delete();

The Versions

28/02 2018

dev-master

9999999-dev

Notes for Laravel 5 Models

  Sources   Download

by Dan Castanera