P
P
Prodion2019-12-25 04:52:57
Laravel
Prodion, 2019-12-25 04:52:57

The belongsTo analog of hasManyThrough?

How to create an inverse relationship for hasManyThrough?

class Manufacturer extends Model
{
    public function collections()
    {
        return $this->hasMany('App\Collection');
    }

    public function colors()
    {
        return $this->hasManyThrough('App\Color', 'App\Collection');
    }
}

class Color extends Model
{
    public function manufacturer()
    {
        //
    }

    public function collection()
    {
        return $this->belongsTo('App\Collection');
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Smirnov, 2019-12-25
@Bzdykin

Check out this package.
Also read the discussion on a similar issue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question