unisharp / ratable
let object can be rated
dev-master / 1.0.x-dev
2018-05-23 11:08 UTC
Requires
- php: ^7.1
- illuminate/config: >5.5.0
- illuminate/support: >5.5.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.16.1
- mockery/mockery: ^0.9.4
- orchestra/database: ~3.6.0
- orchestra/testbench: ~3.6.0
- phpunit/phpunit: ^7.0
- sebastian/diff: ^3.0.0
This package is auto-updated.
Last update: 2024-10-21 21:32:35 UTC
README
Provide a trait to multiple models to rate easliy.
Installation
composer require unisharp/ratable dev-master
Configuration
Set provider modules in config/app.php
return [ 'providers' => [ UniSharp\Ratable\Providers\RatableServiceProvider:class ] ];
Usages
Use trait in the model
namespace App; use Illuminate\Database\Eloquent\Model; use UniSharp\Ratable\Traits\Ratable; class Movie extends Model { use Ratable; }
Rate your model with grade and/or description
$movie = new Movie(); $movie->rates()->create([ 'grade' => 10, 'description' => 'Excellent' ]);
Get your model's average rate
$movie = new Movie(); $movie->rates()->saveMany( new UniSharp\Ratable\Models\Rate(['grade' => 10, 'description' => 'Excellent'], new UniSharp\Ratable\Models\Rate(['grade' => 5, 'description' => 'Not Bad'] ); $movie->average() // 7.5
Get a rate's giver and model
$movie = new Movie(); $rate = $movie->rates()->create([ 'grade' => 10, 'description' => 'Excellent' ]); // giver $rate->user; // model $rate->ratable;