---
title: "Preparing your models — Reports for Laravel | Roundly"
description: "Add GivesReports to models that file reports and HasReports to models that can be reported; Reporter and Reportable are optional markers."
url: https://roundly-consulting.com/open-source/docs/reports-for-laravel/preparing-models
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Reports for Laravel](https://roundly-consulting.com/open-source/docs/reports-for-laravel.md)

# Preparing your models

Add the GivesReports trait to models that file reports, and HasReports to models that can be reported:

```php
use Illuminate\Database\Eloquent\Model;
use RoundlyConsulting\Reports\Contracts\Reportable;
use RoundlyConsulting\Reports\Contracts\Reporter;
use RoundlyConsulting\Reports\Traits\GivesReports;
use RoundlyConsulting\Reports\Traits\HasReports;

class User extends Model implements Reporter
{
    use GivesReports;
}

class Post extends Model implements Reportable
{
    use HasReports;
}
```

Reporter and Reportable are empty marker interfaces — implement them for type-hinting if you like; the traits do the work.

## What GivesReports adds

```php
$user->givenReports;                       // every report the user has filed
$user->givenReports()->pending()->count();  // relation + Report scopes

$user->giveReportTo($post);                 // file a report — returns the Report
$user->report($post);                       // a PendingReport with the reporter pre-set
                                            // (both go through the manager, so Reports::fake() records them)
```

- givenReports() — a MorphMany of every report the model has filed.
- giveReportTo($model, ?$description, ?$reason) — file a report in one call and get the Report back.
- report($model) — start a PendingReport with this model as the reporter.

## What HasReports adds

```php
$post->reports;              // every report against the post
$post->pendingReports;       // open reports only — Pending and InReview
$post->reportsCount();       // int
$post->hasBeenReported();    // bool
$post->isReportedBy($user);  // bool
```

- reports() and pendingReports() — MorphMany relations; pendingReports covers both open statuses.
- reportsCount(), hasBeenReported(), isReportedBy() — counting and lookup helpers.
- withReportCounts(), mostReported(), reportedMoreThan() — query scopes (see Aggregation & querying).

## A model that files and receives reports

Users often report other users. One model can use both traits — they compose without any conflict resolution:

```php
use Illuminate\Database\Eloquent\Model;
use RoundlyConsulting\Reports\Contracts\Reportable;
use RoundlyConsulting\Reports\Contracts\Reporter;
use RoundlyConsulting\Reports\Traits\GivesReports;
use RoundlyConsulting\Reports\Traits\HasReports;

class User extends Model implements Reporter, Reportable
{
    use GivesReports;
    use HasReports;
}
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/reports-for-laravel.md)
