PHP code example of kivicms / laravel-review-rateable
1. Go to this page and download the library: Download kivicms/laravel-review-rateable 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/ */
kivicms / laravel-review-rateable example snippets
namespace App;
use Kivicms\ReviewRateable\Contracts\ReviewRateable;
use Kivicms\ReviewRateable\Traits\ReviewRateable as ReviewRateableTrait;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements ReviewRateable
{
use ReviewRateableTrait;
}
$user = User::first();
$post = Post::first();
$rating = $post->rating([
'title' => 'This is a test title',
'body' => 'And we will add some shit here',
'customer_service_rating' => 5,
'quality_rating' => 5,
'friendly_rating' => 5,
'pricing_rating' => 5,
'rating' => 5,
'recommend' => 'Yes',
'approved' => true, // This is optional and defaults to false
], $user);
dd($rating);
// Get approved ratings
$ratings = $post->getApprovedRatings($post->id, 'desc');
// Get not approved ratings
$ratings = $post->getNotApprovedRatings($post->id, 'desc');
// Get all ratings whether approved or not
$ratings = $post->getAllRatings($post->id, 'desc');
// Get the most recent ratings (limit and sort are optional)
// Limit default is 5, sort default is desc
$ratings = $post->getRecentRatings($post->id, 5, 'desc');
// Get the most recent user ratings (limit and sort are optional)
// Limit default is 5, approved default is true, sort default is desc
$userRatings = $post->getRecentUserRatings($user->id, 5, true, 'desc');
// Get Overall Average Rating
$post->averageRating()
// Get Customer Service Average Rating
$post->averageCustomerServiceRating()
// Get Quality Average Rating
$post->averageQualityRating()
// Get Friendly Average Rating
$post->averageFriendlyRating()
// Get Price Average Rating
$post->averagePricingRating()
$post->averageRating(2) //round to 2 decimal place
$post->averageRating(null, true) //get only approved average rating
$post->ratingPercent()
$post->ratingPercent(10)); // Ten star rating system
// Note: The value passed in is treated as the maximum allowed value.
// This defaults to 5 so it can be called without passing a value as well.