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

Read Audit implementation from MorphMany #871

Conversation

gisostallenberg
Copy link
Contributor

@gisostallenberg gisostallenberg commented Oct 10, 2023

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',
        );
    }

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<AuditMyAuditableModel>
     */
    public function audits(): MorphMany
    {
        return $this->morphMany(
            AuditMyAuditableModel::class,
            'auditable',
        );
    }
```
@MortenDHansen
Copy link
Contributor

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

@MortenDHansen MortenDHansen added help wanted Assistance or contributions needed enhancement An improvement or new feature labels Oct 11, 2023
@erikn69
Copy link
Contributor

erikn69 commented Apr 22, 2024

Fix on a08c673

@erikn69 erikn69 closed this Apr 22, 2024
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 help wanted Assistance or contributions needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants