Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request : add types of ratings (categories) #72

Open
agelospanagiotakis opened this issue Dec 19, 2024 · 2 comments
Open

feature request : add types of ratings (categories) #72

agelospanagiotakis opened this issue Dec 19, 2024 · 2 comments

Comments

@agelospanagiotakis
Copy link

add types of ratings (categories)

@willvincent
Copy link
Owner

I don't think any changes are necessary to this package to facilitate this.

@agelospanagiotakis
Copy link
Author

I guess that you mean one could

  • create a RatingCategory model and associate it with the Rating model
  • Add a category field to the ratings table:
Schema::table('ratings', function (Blueprint $table) {
    $table->string('category')->nullable(); // or use an enum if categories are predefined
});

and then

  • Filter ratings by category:
$product = Product::find(1);
$qualityRatings = $product->ratings()->where('category', 'quality')->get();
$priceRatings = $product->ratings()->where('category', 'price')->get();

also maybe use a separate model for categories (if needed):

// RatingCategory model
class RatingCategory extends Model {
    public function ratings() {
        return $this->hasMany(Rating::class);
    }
}

// Rating model
class Rating extends Model {
    public function category() {
        return $this->belongsTo(RatingCategory::class);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants