S
S
Stanislav Pochepko2016-06-06 15:39:23
MySQL
Stanislav Pochepko, 2016-06-06 15:39:23

How to make model feedback on itself in Eloquent Laravel?

You need to implement category exclusion. That is, to one category, others are indicated that are considered mutually exclusive.
In the Category model, I made a link

Category {

public function excludes()
    {
        return $this->belongsToMany(Category::class, 'excludes_cetegories', 'category_id', 'exclude_id');
    }

}

But you can't get feedback. That is,
Milk excludes Vegetables and Fruits, but Vegetables and Fruits do not have this exception. Do I have to duplicate records or is there a way to do everything on one record?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
6
65536, 2016-06-08
@65536

make the second method (think of a name)
public function excludes2()
{
return $this->belongsToMany(Category::class, 'excludes_cetegories', 'exclude_id', 'category_id');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question