Skip to content

Commit

Permalink
Add error relation trait (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean authored Mar 7, 2022
1 parent 523c3bb commit 97ba454
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ If you don't want to group you can call `dontGroup()`.

You can hide errors from the index by calling `hideFromIndex()`.


## Model relation

When using the `withModel` method you can retrieve errors for a specific model.
The `\JustBetter\ErrorLogger\Traits\HasErrors` trait contains this relation with the name `errors()`

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
14 changes: 14 additions & 0 deletions src/Traits/HasErrors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace JustBetter\ErrorLogger\Traits;

use Illuminate\Database\Eloquent\Relations\MorphMany;
use JustBetter\ErrorLogger\Models\Error;

trait HasErrors
{
public function errors(): MorphMany
{
return $this->morphMany(Error::class, 'model');
}
}

0 comments on commit 97ba454

Please sign in to comment.