Skip to content
New issue

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

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

Already on GitHub? # 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);
    }
}

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

No branches or pull requests

2 participants