0

I need a bit of help in showing user the ads of the those categories that he has seen previously. Its more like suggestion system, the system should generate a intelligent combination of most viewed and new categories. We are recording the ads view and we have categories of viewed ads

Ads.php

class Ads extends Model
{
    public function category(){
        return $this->belongsTo(Category::class , 'category_id');
    }
}

Adcounts.php -> Used as pivot for storing views and categories

class adcounts extends Model
{
    
    public function ad(){
        return $this->belongsTo(Ads::class , 'post_id');
    }
    public function category(){
        return $this->belongsTo(Category::class , 'category_id');
    }
}

Category.php

class Category extends Model
{
    public function ads(){
        return $this->hasMany(Ads::class);
    }
}

What I need is to show the user ads of those categories which he has seen previously.

Saad
  • 21
  • 1
  • 7
  • 1
    Welcome to SO. You need to provide more information about the problem including examples of what you have tried, what doesn't work and what you expect. Please read the [how to ask a good question](https://stackoverflow.com/help/how-to-ask) guide. – Peppermintology May 29 '21 at 09:41
  • Actually I think sharing code won't help as I have a long code but that's not relevant to the actual problem. At the moment, what I have is a list of Ads user views and its category. What I need now is to show the user according to that data. And I can't do sorting because it has to be mixed categories. – Saad May 29 '21 at 10:39
  • 1
    Providing some code will be helpful as we know nothing of your code such as models and their relationships and so answers would be speculative. We don't need all your code, just what is relevant. – Peppermintology May 29 '21 at 10:45
  • Actually I can tell you what you mentioned earlier. We haves Ad model, Category model. Every ad belongsTo a category. We have a views table where every ad view is recorded with ad_id and category_id. Now I have a percentage of what a user has seen previously category-wise. But I want to list further ads according to most watched categories. If you still need code, let me know which part you need but at the current moment, I am just trying to fetch percentage of categories and code is not very well written (done by previous dev) – Saad May 29 '21 at 10:50
  • @Saad You should add your minimal models definitions which shows the relation between them, as you mentioned *Now I have a percentage of what a user has seen previously category-wise* please show how this is stored/calculated and you exact desired output, this can be be showing a sample data for your tables and based on the sample data add your expected output. The way you are explaining details in raw form won't help you instead add all the relevant detail in your question because not every visitor will read all comments in order to understand your issue they probably will flag this question. – M Khalid Junaid May 29 '21 at 15:06

0 Answers0