laravel-auditing icon indicating copy to clipboard operation
laravel-auditing copied to clipboard

Read Audit implementation from MorphMany

Open gisostallenberg opened this issue 1 year ago • 1 comments

To allow a different Audit implementation per model the implementation should be deducted from the MorphMany given by the Auditable::audits method.

This will allow having a main Audit implementation (which defaults to OwenIt\Auditing\Models\Audit), but also have a different implementation once the Auditable::audits method is overwritten.

Example:

class MyAuditable extends Model implements AuditableContract
{
    use Auditable;

    /**
     * @return MorphMany<AuditOfMyAuditableModel>
     */
    public function audits(): MorphMany
    {
        return $this->morphMany(
            AuditOfMyAuditableModel::class,
            'auditable',
        );
    }

gisostallenberg avatar Oct 10 '23 09:10 gisostallenberg

It is a good idea! - I do need some test coverage of the feature though.

MortenDHansen avatar Oct 11 '23 06:10 MortenDHansen

Fix on https://github.com/owen-it/laravel-auditing/commit/a08c673e31bc4d55b6f5b5dd8cc9ab9085022d15

erikn69 avatar Apr 22 '24 13:04 erikn69