1. Go to this page and download the library: Download laravel-interaction/rate 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/ */
laravel-interaction / rate example snippets
use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Rate\Concerns\Rater;
class User extends Model
{
use Rater;
}
use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Rate\Concerns\Ratable;
class Channel extends Model
{
use Ratable;
}
use LaravelInteraction\Rate\Tests\Models\Channel;
/** @var \LaravelInteraction\Rate\Tests\Models\User $user */
/** @var \LaravelInteraction\Rate\Tests\Models\Channel $channel */
// Rate to Ratable
$user->rate($channel);
// rate is only allowed to be called once
$user->rateOnce($channel);
$user->unrate($channel);
$user->toggleRate($channel);
// Compare Ratable
$user->hasRated($channel);
$user->hasNotRated($channel);
// Get rated info
$user->raterRatings()->count();
// with type
$user->raterRatings()->withType(Channel::class)->count();
// get rated channels
Channel::query()->whereRatedBy($user)->get();
// get rated channels doesnt rated
Channel::query()->whereNotRatedBy($user)->get();