PHP code example of rezaghz / laravel-reports

1. Go to this page and download the library: Download rezaghz/laravel-reports library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rezaghz / laravel-reports example snippets


'providers' => [
    Rezaghz\Laravel\Reports\ReportsServiceProvider::class,
],

use Rezaghz\Laravel\Reports\Traits\Reports;
use Rezaghz\Laravel\Reports\Contracts\ReportsInterface;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements ReportsInterface
{
    use Reports;
}

use Illuminate\Database\Eloquent\Model;
use Rezaghz\Laravel\Reports\Traits\Reportable;
use Rezaghz\Laravel\Reports\Contracts\ReportableInterface;

class Article extends Model implements ReportableInterface
{
    use Reportable;
}

$user->reportTo($article, 'spam');

$article->report('spam'); // current login user
$article->report('spam', $user);

$user->removeReportFrom($article);

$article->removeReport(); // current login user
$article->removeReport($user);

$user->toggleReportOn($article, 'spam');

$article->toggleReport('spam'); // current login user
$article->toggleReport('spam', $user);

$user->isReportedOn($article));

$article->is_reported; // current login user
$article->isReportBy(); // current login user
$article->isReportBy($user);

$article->reportSummary();
$article->report_summary;

// example
$article->report_summary->toArray();
// output
/*
[
    "spam" => 5,
    "violence" => 2,
    "illegal_drugs" => 4,
    "child_abuse" => 1
]
*/

$article->reportsBy();

Article::whereReportedBy()->get(); // current login user

Article::whereReportedBy($user)->get();
Article::whereReportedBy($user->id)->get();

// It will return the Report object that is reported by given user.
$article->reported($user);
$article->reported(); // current login user
$article->reported; // current login user

$user->reportedOn($article);
bash
$ php artisan migrate