2017 © Pedro Peláez
 

utils notes

Model notes.

image

vuer/notes

Model notes.

  • Thursday, October 6, 2016
  • by vuer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 153 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 16 % Grown

The README.md

Notes (Laravel 5 Package)

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Installation

You can install this package via composer using this command:, (*2)

composer require vuer/notes

Next, you must install the service provider:, (*3)

``` php // config/app.php 'providers' => [ ... Vuer\Notes\NotesServiceProvider::class, ];, (*4)


Publish migration and configuration file:

php artisan vendor:publish, (*5)


After the migration has been published you can create the notes table by running the migrations:

php artisan migrate, (*6)


If you want you can change models in notes config file (config/notes.php):

/* * The class name of the note model to be used. */ 'note_model' => \Vuer\Notes\Models\Note::class,, (*7)

/* * The class name of the author model to be used. */ 'author_model' => \App\User::class,, (*8)


## Usage ### Preparing your model To associate notes with a model, the model must implement the following trait: ``` php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Vuer\Notes\Traits\HasNotes; class User extends Model { use HasNotes; ... }

Creating notes

You can create a note for the model like this: ``` php $user = User::find(1); $note = $user->createNote(['body' => 'Lorem ipsum...']);, (*9)

To save note author you should add second parameter:
``` php
$note = $user->createNote(['body' => 'Lorem ipsum...'], \Auth::user());

If you want to save author name you need to create getNotesAuthorName method in author class. It is useful if you want to delete users and keep informations about notes authors. ``` php <?php, (*10)

namespace App;, (*11)

use Illuminate\Foundation\Auth\User as Authenticatable; use Vuer\Notes\Traits\HasNotes;, (*12)

class User extends Authenticatable { use HasNotes;, (*13)

public function getNotesAuthorName()
{
    return trim(sprintf('%s %s', $this->name, $this->surname));
}

}, (*14)

You can get all notes or 1 note:
``` php
$notes = $user->notes;
$note = $user->note;

You can use it to create model description: ``` php protected $fillable = [ 'description', ];, (*15)

public function setDescriptionAttribute($value) { $this->updateOrCreateNote([], ['body' => $value]); }, (*16)

public function getDescriptionAttribute() { return $this->note ? $this->note->body : ''; } ```, (*17)

The Versions

06/10 2016

dev-master

9999999-dev

Model notes.

  Sources   Download

MIT

by Avatar vuer

laravel notes noteable vuer model notes

06/10 2016

1.1.0

1.1.0.0

Model notes.

  Sources   Download

MIT

by Avatar vuer

laravel notes noteable vuer model notes

06/10 2016

1.0.0

1.0.0.0

Model notes.

  Sources   Download

MIT

by Avatar vuer

laravel notes noteable vuer model notes