https://github.com/inpin/lara-report
Trait for Laravel Eloquent models to allow easy implementation of a "user report" feature.
https://github.com/inpin/lara-report
eloquent error fault inpin issue larareport laravel laravel5 php report reportable spam trait
Last synced: 7 months ago
JSON representation
Trait for Laravel Eloquent models to allow easy implementation of a "user report" feature.
- Host: GitHub
- URL: https://github.com/inpin/lara-report
- Owner: inpin
- Created: 2018-06-02T07:08:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-09T11:28:45.000Z (over 7 years ago)
- Last Synced: 2025-06-01T13:54:09.394Z (8 months ago)
- Topics: eloquent, error, fault, inpin, issue, larareport, laravel, laravel5, php, report, reportable, spam, trait
- Language: PHP
- Homepage: https://inpinapp.com
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
LaraReport
============
[](https://travis-ci.org/inpin/lara-report)
[](https://github.styleci.io/repos/135795948)
[](https://codeclimate.com/github/inpin/lara-report/maintainability)
[](https://packagist.org/packages/inpin/lara-report)
[](https://packagist.org/packages/inpin/lara-report)
[](https://packagist.org/packages/inpin/lara-report)
[](https://packagist.org/packages/inpin/lara-report)
Trait for Laravel Eloquent models to allow easy implementation of a "user report" feature.
#### Composer Install (for Laravel 5.5 and above)
composer require inpin/lara-report
#### Install and then run the migrations
```php
'providers' => [
\Inpin\LaraReport\LaraReportServiceProvider::class,
],
```
```bash
php artisan vendor:publish --provider="Inpin\LaraReport\LaraReportServiceProvider" --tag=migrations
php artisan migrate
```
#### Setup your models
```php
class Book extends \Illuminate\Database\Eloquent\Model {
use Inpin\LaraReport\Reportable;
}
```
#### Sample Usage
Firstly it needs to be seeded in `larareport_report_items` table.
```php
ReportItem::query()->create([
'type' => 'books',
'title' => 'Price is incorrect',
]);
```
the `type` field is just for categorizing, I suggest to put your model morph name into it.
```php
// Create an empty report by currently logged in user.
$book->createReport();
// Create a report on $book object with "report item id" of 1 and 2, with message of null,
// and put current logged in user form default guard as reporter.
$book->createReport([1, 2]);
// Create a report on $book object with "report item id" of 1 and 2, and put user message of "some message on it",
// and put current logged in user form default guard as reporter.
$book->createReport([1, 2], 'some message');
// Create a report on $book object with "report item id" of 1 and 2, put user message of "some message on it",
// and put current logged in user form 'api' guard as reporter.
$book->createReport([1, 2], 'some message', 'api');
// Create a report on $book object with "report item id" of 1 and 2, put user message of "some message on it",
// and put $user (3rd param) as reporter.
$book->createReport([1, 2], 'some message', $user');
$book->reports(); // HasMany relation to reports of book.
$book->reports; // Collection of book's reports.
$book->isReported() // check if current logged in user form default guard has reported book.
$book->isReported // check if current logged in user form default guard has reported book.
$book->isReported('api') // check if current logged in user form 'api' guard has reported book.
$book->isReported($user) // check if '$user' has reported book.
$book->reportsCount; // return number of reports on $book.
$book->reportsCount(); // return number of reports on $book.
```
Report objects
```php
$report->assign(); // Assign current logged from default guard as admin of $report
$report->assign('api'); // Assign current logged from 'api' guard as admin of $report
$report->assign($user); // Assign $user as admin of $report
// set resolved_at with current timestamp and assign current logged from default guard as admin of $report
$report->resolve();
// set resolved_at with current timestamp and assign current logged from 'api' guard as admin of $report
$report->resolve('api');
// set resolved_at with current timestamp and assign $user as admin of $report
$report->resolve($user);
// check if $report is resolved or not.
$report->isResolved();
```
#### Credits
- Mohammad Nourinik - http://inpinapp.com