tobymaxham/laravel-helper

Bundle of Laravel helper stuff

v1.4 2019-12-30 19:07 UTC

This package is auto-updated.

Last update: 2024-10-29 05:10:51 UTC


README

Latest Version on Packagist Software License Quality Score StyleCI Total Downloads

Installation

You can install this package via composer:

composer require tobymaxham/laravel-helper

Model Logging

Track User changes

Track if user created, updated or deleted a Model. You have to add these attributes to you database table. By default the fields created_by, updated_by and deleted_by fields will be used.

namespace App;

use TobyMaxham\Helper\Models\Logs\ChangeByUser;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use ChangeByUser;
}

You could also turn off tracking by returning false to the attribute fetching methods:

public function getCreatedByColumn()
{
    return false;
}

Migration

With my MigrationHelper you can automatically add the fields to you migrations file:

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');

            $table->string('title');
            $table->text('content');

            MigrationHelper::addCreatedByUser($table);

            $table->timestamps();
        });
    }

Or you can create all three fields at once by calling MigrationHelper::addChangedByUserFields($table).

Changelog

Please see CHANGELOG for more information what has changed recently.

License

The MIT License (MIT). Please see License File for more information.