This package adds a reviewable feature to your app.
composer require naoray/laravel-reviewable
composer require naoray/laravel-reviewable:1.1.*
composer require naoray/laravel-reviewable:1.0.*
publish config: php artisan vendor:publish --provider="Naoray\LaravelReviewable\LaravelReviewableServiceProvider"
First, add the Naoray\LaravelReviewable\Traits\HasReviews
trait to your model you want to add reviews to.
use Naoray\LaravelReviewable\Traits\HasReviews;
class Post extends Model
{
use HasReviews;
// ...
}
Now you can create a review by:
// from reviewable entity
Post::first()->createReview(5, 'Example review text', $author);
// author is assumed to be logged in and executing this operation
Post::first()->createReview(10);
// with helper
review($post, 5, 'Example Text', $author);
and receive review scores by:
// summarizes all scores
Post::first()->score;
// gives the average of all scores
Post::first()->avg_score;
If you just want to change the global configuration to use your own Review-Model, just create a new Model and reference it in the reviewable.models.review
config.
If you do not want to change the global review
Model you can take a look at this issue for an example configuration.
Run the tests with:
vendor/bin/phpunit
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.