Download the PHP package kamansoft/laravel-blame without Composer
On this page you can find all versions of the php package kamansoft/laravel-blame. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kamansoft/laravel-blame
More information about kamansoft/laravel-blame
Files in kamansoft/laravel-blame
Package laravel-blame
Short Description A tool to easily work with the updated_by and created_by fields on your laravel eloquent models
License MIT
Homepage https://github.com/kamansoft/laravel-blame
Informations about the package laravel-blame
laravel-blame
update_by and created_by fields in your laravel model ?
This is a laravel package that will ease the usage of the normally called created_by and update_by extra fields used to stablish responsabilites on records persistance create or update events, with similar fashion as the "timestamp fields" on Eloquent's models, it automatically fills the fields with the primary key of the currently logged user or with a preconfigured system user id.
Requirements
This packages was build taking in mind that you use laravel with an eloquent user model class as auth provider. So before installing you must make sure that your user eloquent model is set on the providers section of your auth config file like this:
Installation
You can install the package via composer:
Some times your laravel application will perform actions that persists records on the database without an authenticated or logged in user, You can call this user as System User or any other name you want, but you must specify its id or primary key.
To do so you can run the system user command or the package install comand:
The above command will publish the package config file and it will run the system user command with no arguments.
Usage
You must first add the update_by and created_by fields to the table's migration field in order to use it in your models.
Then just make use of the Modelblamer trait on your eloquent models, and its booting method will take care of the rest. Also for the seek of a good practice let your model implement the BlameableInterface on your models. Then your model should look something like this
Commands
This package ships two artisan commands as tools to ease the package usage simplifiying repetitive task like creating or updating the systemuser or adding the updated by and created by fields to your model's table.
Blame FIelds Migration command
This command is primarly intend to be used when you need to update an existing table, adding the created_by and updated_by fields, it needs an argument with the name of the table to update.
When runned the above command will create a new migration file in the database/migrations folder with the name add_blame_fields_to_some_table_name_table with a content similar to this:
System User Command
When used with no param or arguments:
This command creates a new laravel user to be used when no user can be retrived with Auth::user().
When runned with a value throug the optional "--key" param:
The command will check if a user with that id exists and if not it will try to create one with that id.
In both cases the command will set the created system user primary key or id in the project .env file as BLAME_SYSTEM_USER_ID.
All versions of laravel-blame with dependencies
doctrine/dbal Version ^3.5
illuminate/contracts Version ^9.0
spatie/laravel-package-tools Version ^1.13.0