All Projects → WildsideUK → Laravel Userstamps

WildsideUK / Laravel Userstamps

Licence: mit
Laravel Userstamps provides an Eloquent trait which automatically maintains `created_by` and `updated_by` columns on your model, populated by the currently authenticated user in your application.

Projects that are alternatives of or similar to Laravel Userstamps

History Tracker
Laravel Model history tracking made easy
Stars: ✭ 46 (-76.17%)
Mutual labels:  laravel, laravel-package, trait
Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+1046.11%)
Mutual labels:  laravel, laravel-package
Laravel Security Checker
Added Laravel functionality to Enlightn Security Checker. Adds a command to check for, and optionally emails you, vulnerabilities when they affect you.
Stars: ✭ 163 (-15.54%)
Mutual labels:  laravel, laravel-package
Laravel Source Encrypter
Laravel and Lumen Source Code Encrypter
Stars: ✭ 175 (-9.33%)
Mutual labels:  laravel, laravel-package
Laravel Auto Translate
Automatically translate your language files using a translator service
Stars: ✭ 153 (-20.73%)
Mutual labels:  laravel, laravel-package
Schedule
Schedule is a package that helps tracking schedules for your models. If you have workers in a company, you can set schedules for them and see their availability though the time.
Stars: ✭ 155 (-19.69%)
Mutual labels:  laravel, trait
Laravel Selfupdater
This package provides some basic methods to implement a self updating functionality for your Laravel application. Already bundled are some methods to provide a self-update mechanism via Github or some private repository via http.
Stars: ✭ 170 (-11.92%)
Mutual labels:  laravel, laravel-package
Laravel Themer
Multi theme support for Laravel application
Stars: ✭ 142 (-26.42%)
Mutual labels:  laravel, laravel-package
Laravel Identify
📦 📱 Laravel 5 Package to Detect Users Browsers, Devices, Languages and Operating Systems
Stars: ✭ 177 (-8.29%)
Mutual labels:  laravel, laravel-package
Laravel Castable Data Transfer Object
Automatically cast JSON columns to rich PHP objects in Laravel using Spatie's data-transfer-object class
Stars: ✭ 191 (-1.04%)
Mutual labels:  laravel, laravel-package
Laravel Localization Helpers
🎌 Artisan commands to generate and update lang files automatically
Stars: ✭ 190 (-1.55%)
Mutual labels:  laravel, laravel-package
Laravelresources
Speed Up package development for Laravel Apps with API's
Stars: ✭ 152 (-21.24%)
Mutual labels:  laravel, laravel-package
Has Parameters
A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.
Stars: ✭ 149 (-22.8%)
Mutual labels:  laravel, trait
Laravel Early Access
This package makes it easy to add early access mode to your existing application.
Stars: ✭ 160 (-17.1%)
Mutual labels:  laravel, laravel-package
Servermonitor
💓 Laravel package to periodically monitor the health of your server and application.
Stars: ✭ 148 (-23.32%)
Mutual labels:  laravel, laravel-package
Laravel Page Speed
Package to optimize your site automatically which results in a 35%+ optimization
Stars: ✭ 2,097 (+986.53%)
Mutual labels:  laravel, laravel-package
Laravel Cross Eloquent Search
Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.
Stars: ✭ 189 (-2.07%)
Mutual labels:  laravel, laravel-package
Laravel Scout Postgres
PostgreSQL Full Text Search Engine for Laravel Scout
Stars: ✭ 140 (-27.46%)
Mutual labels:  laravel, laravel-package
Laravel Db Profiler
Database Profiler for Laravel Web and Console Applications.
Stars: ✭ 141 (-26.94%)
Mutual labels:  laravel, laravel-package
Laravel Auth Checker
Laravel Auth Checker allows you to log users authentication, devices authenticated from and lock intrusions.
Stars: ✭ 177 (-8.29%)
Mutual labels:  laravel, laravel-package

Build Status Total Downloads Latest Stable Version License

About Laravel Userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains created_by and updated_by columns on your model, populated by the currently authenticated user in your application.

When using the Laravel SoftDeletes trait, a deleted_by column is also handled by this package.

Installing

This package requires Laravel 5.2 or later running on PHP 5.6 or higher.

This package can be installed using composer:

composer require wildside/userstamps

Usage

Your model will need to include a created_by and updated_by column, defaulting to null.

If using the Laravel SoftDeletes trait, it will also need a deleted_by column.

The column type should match the type of the ID colummn in your user's table. In Laravel <= 5.7 this defaults to unsignedInteger. For Laravel >= 5.8 this defaults to unsignedBigInteger.

An example migration:

$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();

You can now load the trait within your model, and userstamps will automatically be maintained:

use Wildside\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;
}

Optionally, should you wish to override the names of the created_by, updated_by or deleted_by columns, you can do so by setting the appropriate class constants on your model. Ensure you match these column names in your migration.

use Wildside\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;

    const CREATED_BY = 'alt_created_by';
    const UPDATED_BY = 'alt_updated_by';
    const DELETED_BY = 'alt_deleted_by';
}

When using this trait, helper relationships are available to let you retrieve the user who created, updated and deleted (when using the Laravel SoftDeletes trait) your model.

$model->creator; // the user who created the model
$model->editor; // the user who last updated the model
$model->destroyer; // the user who deleted the model

Methods are also available to temporarily stop the automatic maintaining of userstamps on your models:

$model->stopUserstamping(); // stops userstamps being maintained on the model
$model->startUserstamping(); // resumes userstamps being maintained on the model

Workarounds

This package works by by hooking into Eloquent's model event listeners, and is subject to the same limitations of all such listeners.

When you make changes to models that bypass Eloquent, the event listeners won't be fired and userstamps will not be updated.

Commonly this will happen if bulk updating or deleting models, or their relations.

In this example, model relations are updated via Eloquent and userstamps will be maintained:

$model->foos->each(function ($item) {
    $item->bar = 'x';
    $item->save();
});

However in this example, model relations are bulk updated and bypass Eloquent. Userstamps will not be maintained:

$model->foos()->update([
    'bar' => 'x',
]);

As a workaroud to this issue two helper methods are available - updateWithUserstamps and deleteWithUserstamps. Their behaviour is identical to update and delete, but they ensure the updated_by and deleted_by properties are maintained on the model.

You generally won't have to use these methods, unless making bulk updates that bypass Eloquent events.

In this example, models are bulk updated and userstamps will not be maintained:

$model->where('name', 'foo')->update([
    'name' => 'bar',
]);

However in this example, models are bulk updated using the helper method and userstamps will be maintained:

$model->where('name', 'foo')->updateWithUserstamps([
    'name' => 'bar',
]);

Sponsors

This open-source software is developed and maintained by WILDSIDE.

License

This open-source software is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].