https://github.com/unisharp/ratable
Provide a trait to multiple models to rate easliy
https://github.com/unisharp/ratable
Last synced: about 1 month ago
JSON representation
Provide a trait to multiple models to rate easliy
- Host: GitHub
- URL: https://github.com/unisharp/ratable
- Owner: UniSharp
- License: mit
- Created: 2018-04-19T04:16:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-23T11:09:19.000Z (about 8 years ago)
- Last Synced: 2025-01-10T12:49:07.470Z (over 1 year ago)
- Language: PHP
- Size: 24.4 KB
- Stars: 2
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ratable
Provide a trait to multiple models to rate easliy.
## Installation
```
composer require unisharp/ratable dev-master
```
## Configuration
Set provider modules in `config/app.php`
```php
return [
'providers' => [
UniSharp\Ratable\Providers\RatableServiceProvider:class
]
];
```
## Usages
Use trait in the model
```php
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
```php
$movie = new Movie();
$movie->rates()->create([
'grade' => 10,
'description' => 'Excellent'
]);
```
Get your model's average rate
```php
$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
```php
$movie = new Movie();
$rate = $movie->rates()->create([
'grade' => 10,
'description' => 'Excellent'
]);
// giver
$rate->user;
// model
$rate->ratable;
```