Download the PHP package jlorente/laravel-identitystamps without Composer
On this page you can find all versions of the php package jlorente/laravel-identitystamps. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jlorente/laravel-identitystamps
More information about jlorente/laravel-identitystamps
Files in jlorente/laravel-identitystamps
Package laravel-identitystamps
Short Description A Laravel plugin to register and keep control of the users who make creations, updates and deletions of models
License BSD-3-Clause
Informations about the package laravel-identitystamps
Laravel IdentityStamps Plugin
A Laravel plugin to register and keep control of users who make creations, updates and deletions of models.
With this plugin, you will manage automatically the control fields "created_by", "updated_by" and "deleted_by" that will store the identity of the users that manipulate the models.
Installation
The preferred way to install this extension is through composer.
With Composer installed, you can then install the extension using the following commands:
or add
to the section of your composer.json
file.
Configuration
Register the ServiceProvider in your config/app.php service provider list.
config/app.php
Usage
On Migrations
You can use the Blueprint method identityStamps() to add nullable "created_by" and "updated_by" UNSIGNED INTEGER equivalent columns. Of course, you can create the columns by yourself with a custom name and type and then configure the Model class with these names, but remember that the type should be the same as the type of the key of your UserModel.
If you use soft deletes, maybe you want to add an identity stamp for the deletion too. You can do this by using the softDeletesIdentityStamps() method that will add a nullable "deleted_by" UNSIGNED INTEGER column.
Attaching the behavior to a Model
To enable identity stamps for a model, use the Jlorente\IdentityStamp\Eloquent\IdentityStamps trait on the model:
Further considerations
Using custom attributes names
You can use your custom attributes names to store the identity by defining class constants on the model.
If you don't like class constants you can also override the trait methods that resolve the identity stamp fields.
Using custom identity id to be stored in the identity fields
By default, the trait will use Laravel's Auth::id() method to retrieve the id that will be stored on the identity stamp fields. Feel free to override the method getIdentityStampValue() to return the value that you want to store in the fields.
License
Copyright © 2019 José Lorente Martín [email protected].
Licensed under the BSD 3-Clause License. See LICENSE.txt for details.