2017 © Pedro Peláez
 

library laravel-createdby

A trait that adds createdBy and updatedBy user relations to your models

image

malhal/laravel-createdby

A trait that adds createdBy and updatedBy user relations to your models

  • Friday, October 21, 2016
  • by malhal
  • Repository
  • 1 Watchers
  • 31 Stars
  • 117 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel-CreatedBy

A trait that adds createdBy and updatedBy user relations to your models., (*1)

First either update your database or add this to a migration for each model:, (*2)

$table->unsignedInteger('created_by_id');
$table->unsignedInteger('updated_by_id');
$table->foreign('created_by_id')
    ->references('id')->on('users')
    ->onDelete('cascade');
$table->foreign('updated_by_id')
    ->references('id')->on('users')
    ->onDelete('cascade');

Finally in your model use:, (*3)

use CreatedBy;

Now whenever a model is created or updated the createdBy and updatedBy relations will be automatically updated., (*4)

Unfortunately you shouldn't use this trait on the User model when using auto-increment keys, this is due to the limitation in MySQL that a field cannot reference the currently being inserted ID. However you can still make use of the Laravel-CreatedByPolicy with the workaround explained in that project. If you are using UUIDs for keys then this problem won't happen., (*5)

There are some extra scope features, e.g., (*6)

To add the join to retrieve the user info from the user table:, (*7)

$query->withCreatedBy()
$query->withUpdatedBy()

To query based on a user:, (*8)

$query->whereCreatedBy($user)

To temporarily disable updates on a save:, (*9)

$model->saveWithoutCreatedBy();

If you would like to utilise this trait as part of a simple secuity model check out the extension of this trait Laravel-CreatedByPolicy., (*10)

Installation

PHP 5.6.4+ and Laravel 5.3+ are required., (*11)

To get the latest version of Laravel CreatedBy, simply require the project using Composer:, (*12)

$ composer require malhal/laravel-createdby dev-master

The Versions

21/10 2016

dev-master

9999999-dev

A trait that adds createdBy and updatedBy user relations to your models

  Sources   Download

MIT

The Requires

 

by Malcolm Hall

laravel framework user models createdby updatedby laravel createdby laravel-createdby malcolm hall malhal

19/09 2016

v1.0.0

1.0.0.0

A trait that adds createdBy and updatedBy user relations to your models

  Sources   Download

MIT

The Requires

 

by Malcolm Hall

laravel framework user models createdby updatedby laravel createdby laravel-createdby malcolm hall malhal