2017 © Pedro Peláez
 

utility eloquent-changed-by-user

This simple trait written for eloquent allows you to automaticly write down id of last user changed the database record.

image

constant-null/eloquent-changed-by-user

This simple trait written for eloquent allows you to automaticly write down id of last user changed the database record.

  • Thursday, February 18, 2016
  • by constant-null
  • Repository
  • 1 Watchers
  • 2 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Saving last user changed database record for Eloquent models (Laravel 5)

Please be aware that this trait uses Auth facade and expects it to implement Illuminate\Contracts\Auth\Guard contract, (*1)

How it works

Quite simple actually, just before saving row to database, this trait gets id of current user using Auth::user()->id (thats why requirements above exists) and write it to specified database field (for more specifics read the Installation and configuration section), (*2)

Installation and configuration

This trait can be installed via composer. Just add following to your composer.json file:, (*3)

{
    "require": {
        "constant-null/eloquent-changed-by": "~0.1"
    }
}

and then run:, (*4)

$ composer update

To start using this trait you need to import it to Eloquent model, (*5)

<?php

use ConstantNull\Eloquent\Support\ChangedByUser;
use Illuminate\Database\Eloquent\Model;

class SomeModel extends Model
{
    use ChangedByUser;

    /* The rest of the your class */
}

and add column to database in which user id will be stored. Like this for example:, (*6)

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class BestMigrationEver extends Migration
{

    public function up()
    {
        Schema::table('some_table', function(Blueprint $table) {
            $table->integer('changed_by')->nullable();
        });
    }

How you can see in example the default column name for user id is changed_by, but it can be easily changed by specifying constant CHANGED_BY in your class body., (*7)

For example i want this column name to be 'last_user_id':, (*8)

<?php

use ConstantNull\Eloquent\Support\ChangedByUser;
use Illuminate\Database\Eloquent\Model;

class SomeModel extends Model
{
    use ChangedByUser;

    const CHANGED_BY = 'last_user_id';

    /* Rest part of the your class */
}

Thats all!, (*9)

The Versions

18/02 2016

dev-master

9999999-dev

This simple trait written for eloquent allows you to automaticly write down id of last user changed the database record.

  Sources   Download

MIT

The Requires

 

by Mark Belotskiy

laravel eloquent

09/12 2015

v0.1.1

0.1.1.0

This simple trait written for eloquent allows you to automaticly write down id of last user changed the database record.

  Sources   Download

MIT

The Requires

 

by Mark Belotskii

09/12 2015

v0.1.0

0.1.0.0

This simple trait written for eloquent allows you to automaticly write down id of last user changed the database record.

  Sources   Download

MIT

The Requires

 

by Mark Belotskii