Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Audit Model #211

Closed
Kaylakaze opened this issue Mar 16, 2017 · 6 comments
Closed

Configurable Audit Model #211

Kaylakaze opened this issue Mar 16, 2017 · 6 comments
Labels
enhancement An improvement or new feature

Comments

@Kaylakaze
Copy link

There should be a way to declare a custom Audit model. Since it extends from the default Eloquent model, it is currently incompatible with MongoDB. Simply changing which Model it "use"s worked with no problems, but editing vendor files is generally not a good idea.

@quetzyg quetzyg added the enhancement An improvement or new feature label Mar 17, 2017
@quetzyg
Copy link
Contributor

quetzyg commented Mar 17, 2017

Hi @Kaylakaze,

I'm assuming you changed the model being extended in the Audit class?
What's the class/package you're using for MongoDB?

@Kaylakaze
Copy link
Author

I changed the from Illuminate\Eloquent\Model to Jenssegers\Mongodb\Eloquent\Model. My thought was it'd be easy enough for the end user to make their own copy of Audit in their app folder and change it how they need to and reference that in the config.

@quetzyg
Copy link
Contributor

quetzyg commented Jul 2, 2017

This issue should now be fixed in master. Try it out and let me know how it went. I'll close the issue once I get positive feedback.

I'll have to update the documentation, but what needs to be done is:

<?php
namespace App\Models;

use Jenssegers\Mongodb\Eloquent\Model;
use OwenIt\Auditing\Audit as AuditTrait;
use OwenIt\Auditing\Contracts\Audit as AuditContract;

class Audit extends Model implements AuditContract
{
    use AuditTrait;

    /**
     * {@inheritdoc}
     */
    protected $guarded = [];

    /**
     * {@inheritdoc}
     */
    protected $casts = [
        'old_values' => 'json',
        'new_values' => 'json',
    ];
}

This is for you too, @bsormagec!

@quetzyg
Copy link
Contributor

quetzyg commented Jul 3, 2017

Actually, I might be missing a few more things, hold on.

@quetzyg
Copy link
Contributor

quetzyg commented Jul 3, 2017

OK, so...

Besides implementing an Audit class (see previous example), you'll have to define the implementation you want to use in the configuration, like so:

return [
    // ...

    'implementation' => App\Models\Audit::class,

    // ...
];

Don't forget to try the latest code in master.

EDIT: The documentation has been updated.

@quetzyg
Copy link
Contributor

quetzyg commented Jul 9, 2017

Marking issue as solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement or new feature
Projects
None yet
Development

No branches or pull requests

2 participants