2017 © Pedro Peláez
 

package lara-report

Add Reportable trait to Laravel Eloquent models

image

inpin/lara-report

Add Reportable trait to Laravel Eloquent models

  • Saturday, June 9, 2018
  • by enourinick
  • Repository
  • 1 Watchers
  • 2 Stars
  • 83 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

LaraReport

Build Status StyleCI Maintainability Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Trait for Laravel Eloquent models to allow easy implementation of a "user report" feature., (*2)

Composer Install (for Laravel 5.5 and above)

composer require inpin/lara-report

Install and then run the migrations

'providers' => [
    \Inpin\LaraReport\LaraReportServiceProvider::class,
],
php artisan vendor:publish --provider="Inpin\LaraReport\LaraReportServiceProvider" --tag=migrations
php artisan migrate

Setup your models

class Book extends \Illuminate\Database\Eloquent\Model {
    use Inpin\LaraReport\Reportable;
}

Sample Usage

Firstly it needs to be seeded in larareport_report_items table., (*3)

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., (*4)

// 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, (*5)

$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

The Versions

09/06 2018

dev-master

9999999-dev

Add Reportable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 spam error report issue fault reportable

09/06 2018

1.0.3

1.0.3.0

Add Reportable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 spam error report issue fault reportable

05/06 2018

1.0.2

1.0.2.0

Add Reportable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 spam error report issue fault reportable

04/06 2018

1.0.1

1.0.1.0

Add Reportable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 spam error report issue fault reportable

03/06 2018

1.0.0

1.0.0.0

Add Reportable trait to Laravel Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mohammad Nourinik

laravel eloquent trait laravel5 spam error report issue fault reportable