Home - Scripts - Website Development

  • 08 September 2025

Know How to Implement Rating/Review System in Laravel

by Pragati S. 3 minute read 4 views

Optimizing SEO titles, meta tags and Open Graph tags in Next.js improves visibility, improves click-through rates and boosts rankings in web development.

Key Points

  • Products with 5-star ratings experience 70% more purchases than those with unrated or low ratings.
  • User reviews foster customer trust and loyalty, boosting repeat purchase rates by 50% annually.
  • 70% of buyers read at least five reviews before making an online purchase.

In today’s digital ecosystem, user feedback has become a crucial factor for trust, engagement, and conversion. Whether you are developing an eCommerce store, a SaaS platform, or a services marketplace, a robust rating and review system increases transparency and helps users make informed decisions. For developers using Laravel, integrating such a feature is both scalable and straightforward.

This guide walks you through creating a star-based rating and review system in Laravel, using Bootstrap for the UI and jQuery for interactive star selection. It covers the MVC architecture, database interaction, and dynamic updates, perfect for developers building custom web development solutions or offering website development services.

Step 1: Define Routes

In Laravel, routes connect URL endpoints to controller methods. They handle user actions like submitting a review or viewing product details.

Open routes/web.php and add:

                                        use App\Http\Controllers\ReviewController;

Route::post('/save-review', [ReviewController::class, 'saveReview'])->name('save.review');
Route::get('/product-details/{id}', [ReviewController::class, 'productDetails'])->name('product.details');
                                    

  • save-review: Submits the review and rating to the database.
  • product-details/{id}: Displays product information and associated reviews.

Defining clean RESTful routes ensures better maintainability and scalability in custom web development projects.

Step 2: Set Up Database Table

The database stores user reviews and ratings for products. Use Laravel migrations to create a reviews table:

                                        php artisan make:migration create_reviews_table --create=reviews

In the migration file:
Schema::create('reviews', function (Blueprint $table) {
    $table->id();
    $table->foreignId('product_id')->constrained()->onDelete('cascade');
    $table->foreignId('user_id')->constrained()->onDelete('cascade');
    $table->tinyInteger('rating')->unsigned()->check('rating BETWEEN 1 AND 5');
    $table->text('review')->nullable();
    $table->timestamps();
});

Run the migration:
php artisan migrate
                                    

A well-designed database is crucial for custom web development.

Step 3: Create the Review Model

The model handles all database interactions and abstracts SQL logic.

Create the file app/Models/Review.php:

                                        namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Review extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'product_id',
        'rating',
        'review',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public static function averageRating($productId)
    {
        return self::where('product_id', $productId)->avg('rating') ?? 0;
    }

    public static function getReviews($productId)
    {
        return self::with('user')
                   ->where('product_id', $productId)
                   ->orderBy('created_at', 'desc')
                   ->get();
    }
}
                                    

This model guarantees reusable, secure logic for all website development services that involve user-generated content.

Step 4: Create the Review Controller

Controllers manage user inputs, collaborate with models, and display views.

Create the file app/Http/Controllers/ReviewController.php:

                                        namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Review;
use App\Models\Product;
use Illuminate\Support\Facades\Auth;

class ReviewController extends Controller
{
    public function saveReview(Request $request)
    {
        $request->validate([
            'product_id' => 'required|exists:products,id',
            'rating' => 'required|integer|min:1|max:5',
            'review' => 'nullable|string|max:1000',
        ]);

        Review::create([
            'product_id' => $request->product_id,
            'user_id' => Auth::id(),
            'rating' => $request->rating,
            'review' => $request->review,
        ]);

        return redirect()->route('product.details', $request->product_id)
                         ->with('success', 'Review submitted successfully!');
    }

    public function productDetails($id)
    {
        $product = Product::findOrFail($id);
        $reviews = Review::getReviews($id);
        $averageRating = Review::averageRating($id);

        return view('reviews_view', compact('product', 'reviews', 'averageRating'));
    }
}
                                    

Effective controllers simplify the process of hiring Laravel developers for complex custom web development projects.

Step 5: Create the View – reviews_view.blade.php

Views display the product, rating form, and user reviews using HTML, Bootstrap, and jQuery.

                                        <!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Rating & Review</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container pt-3">
    <div class="row">
        <div class="col-md-3 text-center">
            <img src="{{ asset($product->image) }}" alt="{{ $product->name }}" class="img-thumbnail">
        </div>
        <div class="col-md-5">
            <h4>{{ $product->name }}</h4>
            <p>{{ $product->description }}</p>
        </div>
        <div class="col-md-4">
            <div class="card p-3">
                <a href="#" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#ratingModal">
                    <i class="bi bi-star"></i> Write A Review
                </a>
            </div>
        </div>
    </div>
</div>

<!-- Rating Modal -->
<div class="modal fade" id="ratingModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{{ route('save.review') }}" method="POST">
                @csrf
                <div class="modal-header">
                    <h5 class="modal-title">Rate & Review This Product</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" name="product_id" value="{{ $product->id }}">
                    <div class="add_rating" data-rating="0">
                        <i class="bi bi-star"></i>
                        <i class="bi bi-star"></i>
                        <i class="bi bi-star"></i>
                        <i class="bi bi-star"></i>
                        <i class="bi bi-star"></i>
                    </div>
                    <input type="hidden" id="hidden_rating" name="rating" value="0">
                    <div class="form-group mt-3">
                        <label for="review">Your Review</label>
                        <textarea name="review" class="form-control" rows="3"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Submit Review</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Display Reviews -->
<div class="container mt-4">
    <h3>User Reviews</h3>
    <p>Average Rating: <strong>{{ round($averageRating, 2) }}/5</strong></p>

    @forelse($reviews as $review)
        <div class="border p-3 mb-2">
            <strong>{{ $review->user->name }}</strong> rated {{ $review->rating }}/5
            <p>{{ $review->review }}</p>
            <small>{{ $review->created_at }}</small>
        </div>
    @empty
        <p>No reviews yet. Be the first to write one!</p>
    @endforelse
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('.add_rating i.bi-star').on('click', function() {
        let rating = $(this).index() + 1;
        $('#hidden_rating').val(rating);
        $(this).siblings().addBack().each(function(index) {
            $(this).toggleClass('bi-star-fill', index < rating).toggleClass('bi-star', index >= rating);
        });
    });
});
</script>
</body>
</html>
                                    

This front-end provides an intuitive UI and supports website development services with a professional, responsive design.

Final Tips & Best Practices

  • Security: Validate all inputs to prevent XSS or SQL injection.
  • Authentication: Only logged-in users can submit reviews.
  • AJAX Submission: Enhance UX by avoiding page reloads.
  • Caching: Cache average ratings for large catalogs.
  • Extensibility: Add likes, filtering, or abuse reporting.

By following these steps, businesses can leverage custom web development solutions, hire expert Laravel developers, and integrate a fully functional rating/review system in their web platforms.

Final Words

This guide offers a comprehensive Laravel-based rating and review system, perfect for eCommerce, SaaS dashboards, or review-focused web apps. It’s scalable, modular, and ideal for hiring Laravel developers or companies providing website development services.

Tech Stack & Version

Frontend

  • Bootstrap
  • jQuery
  • HTML

Backend

  • Laravel
  • PHP
  • MVC

Deployment

  • cPanel
  • Heroku
  • VPS
img

©2025Digittrix Infotech Private Limited , All rights reserved.