PHP code example of fajarwz / laravel-review
1. Go to this page and download the library: Download fajarwz/laravel-review 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/ */
fajarwz / laravel-review example snippets
use Fajarwz\LaravelReview\Traits\CanBeReviewed;
class Mentor extends Model
{
use CanBeReviewed;
// Optionally, use CanReview if the model can also act as a reviewer
// use CanReview;
}
use Fajarwz\LaravelReview\Traits\CanReview;
class Mentee extends Model
{
use CanReview;
}
$mentee = Mentee::find(1);
$mentor = Mentor::find(1);
// Create an approved review
$mentee->review($mentor, 4.5);
// Create an unapproved review
$mentee->review($mentor, 3.0, 'Needs improvement', false);
$mentee->updateReview($mentor, 5, 'Mentor is even better now!');
$mentee->unreview($mentor);
$review = $mentor->receivedReviews()->first();
$review->approve();
$review = $mentor->receivedReviews()->first();
$review->unapprove();
$mentor->receivedReviews()->get();
$mentor->latestReceivedReviews()->paginate();
$mentor->topRatedReceivedReviews()->paginate();
$mentor->receivedReviews()->withUnapproved()->get();
Mentor::with('receivedReviews.reviewer')->paginate();
$review = $mentor->getReceivedReview($mentee);
$review = $mentor->getReceivedReview($mentee, $
$mentee->givenReviews()->get();
Mentee::with('givenReviews.reviewable')->paginate();
$review = $mentee->getGivenReview($mentor);
$review = $mentor->getGivenReview($mentee, $
if ($mentor->hasReceivedReview($mentee)) {
// The mentor has received a review from the mentee
}
$f ($mentor->hasReceivedReview($mentee, $rom the mentee
}
if ($mentee->hasGivenReview($mentor)) {
// The mentee has given a review to the mentor
}
$f ($mentee->hasGivenReview($mentor, $o the mentor
}
use Fajarwz\LaravelReview\Models\Review;
$review = Review::find($id);
$review->approve();
$review = Review::find($id);
$review->unapprove();
$review = Review::find($id);
if ($review->isApproved()) {
// The review is approved
}
$approvedReviews = Review::all();
$allReviews = Review::withUnapproved()->get();
$review = Review::find($id);
$reviewer = $review->reviewer;
$review = Review::find($id);
$reviewable = $review->reviewable;
use Fajarwz\LaravelReview\Models\ReviewSummary;
$reviewSummary = ReviewSummary::find($id);
$reviewable = $reviewSummary->reviewable;
bash
php artisan vendor:publish --provider="Fajarwz\LaravelReview\LaravelReviewServiceProvider"
php artisan migrate