inpin / lara-report
为 Laravel Eloquent 模型添加可报告特性
1.0.3
2018-06-09 11:22 UTC
Requires
- php: >=7.0
- illuminate/database: >=5.0
- illuminate/support: >=5.0
- laravel/framework: >=5.5
Requires (Dev)
- fzaninotto/faker: ~1.4
- mockery/mockery: ~1.0
- orchestra/database: ^3.5
- orchestra/testbench: ^3.5
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2024-09-29 04:31:30 UTC
README
Laravel Eloquent 模型的特性,用于轻松实现“用户报告”功能。
Composer 安装(适用于 Laravel 5.5 及以上版本)
composer require inpin/lara-report
安装并运行迁移
'providers' => [ \Inpin\LaraReport\LaraReportServiceProvider::class, ],
php artisan vendor:publish --provider="Inpin\LaraReport\LaraReportServiceProvider" --tag=migrations
php artisan migrate
设置您的模型
class Book extends \Illuminate\Database\Eloquent\Model { use Inpin\LaraReport\Reportable; }
示例用法
首先需要在 larareport_report_items
表中填充数据。
ReportItem::query()->create([ 'type' => 'books', 'title' => 'Price is incorrect', ]);
type
字段仅用于分类,建议将您的模型形态名称放入其中。
// 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->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();
致谢
- Mohammad Nourinik - http://inpinapp.com