Looking to hire Laravel developers? Try LaraJobs

laravel-user-stamp maintained by jcrodsolutions

Description
Enables automatic user stamp on created_by and updated_by fields within a model.
Last update
2024/10/10 22:00 (dev-main)
License
Links
Downloads
137

Comments
comments powered by Disqus

Laravel User Stamp✒️

PHP Version Packagist Version Packagist Github

Enables automatic user stamp on created_by and updated_by fields within a model.

Usage

Inside any model having the created_by and/or updated_by fields you should use the trait as follows.

use Jcrodsolutions\LaravelUserStamp\App\Traits\UserStampTrait;
use Illuminate\Database\Eloquent\Model;

class  MyModel  extends  Model
{
	use  UserStampTrait;
	protected  $fillable = ['codename','name','created_by','updated_by'];
	// ...
}

Global defaults

Globally, the default field names the trait will try to populate are

  • active
  • created_by
  • updated_by

Whenever you want to change this just publish the vendor config file.

myproject# php artisan vendor:publish

Proceed by selecting the provider "Provider: Jcrodsolutions\LaravelUserStamp\UserStampServiceProvider".

Custom field names in a model

If you need to customize any of the fields in the model you should override the defaults by defining protected variables as the following example


use Jcrodsolutions\LaravelUserStamp\App\Traits\UserStampTrait;
use Illuminate\Database\Eloquent\Model;

class  MyModel  extends  Model
{
	use  UserStampTrait;
	protected  $fillable = ['codename','name','created_by','updated_by'];
	protected  static  $active = 'activo';
	protected  static  $createdBy = 'creado_por';
	protected  static  $updatedBy = 'actualizado_por';
	
	//...
}

License

MIT.