Download the PHP package always-open/laravel-model-auditlog without Composer

On this page you can find all versions of the php package always-open/laravel-model-auditlog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-model-auditlog

Laravel Model Auditlog

Latest Version on Packagist Build Status Total Downloads Maintainability

When modifying a model record, it is nice to have a log of the changes made and who made those changes. There are many packages around this already, but this one is different in that it logs those changes to individual tables for performance and supports real foreign keys.

Installation

You can install the package via composer:

Configuration

Running the above command will publish the config file.

Usage

After adding the proper fields to your table, add the trait to your model.

To generate an auditlog model / migration for your models, use the following command:

Replace \App\User with your own model name. Model / table options can be tweaked in the config file.

If you need to ignore specific fields on your model, extend the getAuditLogIgnoredFields() method and return an array of fields.

Using that functionality, you can add more custom logic around what should be logged. An example might be to not log the title changes of a post if the post has not been published yet.

Working with Pivot Tables

Audit log can also support changes on pivot models as well.

In this example we have a posts and tags table with a post_tags pivot table containing a post_id and tag_id.

Modify the audit log migration replacing the subject_id column to use the two pivot columns.

Create a model for the pivot table that extends Laravel's Pivot class. This class must use the AuditLoggablePivot trait and have a defined $audit_loggable_keys variable, which is used to map the pivot to the audit log table.

Side note: if a column shares the same name in the pivot and a column already in the audit log table (ex: user_id), change the name of the column in the audit log table (ex: audit_user_id) and define the relationship as 'audit_user_id' => 'user_id'.

The two models that are joined by the pivot will need to be updated so that events fire on the pivot model. Currently Laravel doesn't support pivot events so a third party package is required.

Have both models use the PivotEventTrait

Modify the belongsToMany join on both related models to include the using function along with the pivot model. In the Post model:

In the Tag model:

When a pivot record is deleted through detach or sync, an audit log record for each of the keys (ex: post_id and tag_id) will added to the audit log table. The field_value_old will be the id of the record and the field_value_new will be null. The records will have an event type of PIVOT_DELETED (id: 6).

If you need to pull the audit logs through the auditLogs relationship (ex: $post_tag->auditLogs()->get()), support for composite keys is required.

Then use the trait on the pivot audit log model:

For a working example of pivots with the audit log, see laravel-model-auditlog/tests/Fakes, which contains working migrations and models.

Note: Both models must use the AuditLoggable trait (ex: Post and Tag) so that $post->tags()->sync([...]) will work.

Testing

Using Docker

All assets are set up under the docker-compose.yml file. The first time you run the docker image you must build it with the following command:

Then you can bring it up in the background using:

And the image is aliased so you can access its command line via:

From there you can run the tests within an isolated environment

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email @tomschlick / @qschmick instead of using the issue tracker.

Credits

License

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


All versions of laravel-model-auditlog with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
awobaz/compoships Version ^2.0.3
fico7489/laravel-pivot Version ^3.0.1
laravel/framework Version ^8.0|^9.0|^10.0
always-open/laravel-process-stamps Version ^5.0|^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package always-open/laravel-model-auditlog contains the following files

Loading the files please wait ....