S
S
sgoriunov2022-02-18 13:02:20
Laravel
sgoriunov, 2022-02-18 13:02:20

How to implement a relationship through a table in Laravel?

I'm trying to get caracteristics with relations to product_mod_characteristics.

Now for this I do this:

class ProductMod {
    public function characteristics(): HasMany
    {
        return $this->hasMany(ProductModCharacteristic::class);
    }

    public function getCharacteristics(): array
    {
        $characteristicsId = $this->characteristics()
            ->select('characteristic_id')
            ->distinct()
            ->pluck('characteristic_id')
            ->toArray();
/**
затем запрашиваю caracteristics со связью к product_mod_characteristics
*/
}


Is there a way built into the engine?
As far as I understand, the method "One to one through" and "One to many through" will not work here.

Database structure:
fWkP44m.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question