P
P
Pavel Gogolinsky2020-05-30 01:49:37
Laravel
Pavel Gogolinsky, 2020-05-30 01:49:37

How to make a connection through the model?

There are User, Artist and Album.
Album hasMany Artist via albums_artists table. Here is the connection:

// Album
public function artists()
{
    return $this->belongsToMany(Artist::class);
}


Artist hasMany User via artists_users table. Here is the connection:
// Artist
public function users()
{
    return $this->belongsToMany(User::class);
}

The question is how to write a relationship between Album and User through Artist?
// Album
public function users()
{
    // ??
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2020-05-30
@vos_50

You describe the hasManyThrough relationship, not hasMany. Read about it in the documentation, everything is clear there.

J
Jamal Absalimov, 2020-05-30
@JamalWeb

Hello, it seems that this video has the answer, at 6 minutes
https://www.youtube.com/watch?v=PgRcyJe76C8&list=P...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question