I have three models creating a many-to-many relationship
ModelA(id)
ModelB(A.id,C.id)
ModelC(id,name)
How to fetch C.name using model A?
Currently model A hasOne model B, and model C hasMany model B. I tried to relate model A and C using hasOnethrough using model B but it gives me null.
Based on your question
ModelBis your pivot model to handle your relationship.Normally we use pivot tables for many-to-many relationships, in that case you can use the
hasManyThroughmethod.You can try the above function in your
ModelAmodel like you asked and will link tomodelCthrough theModelBThen you can fetch it like a normal relationship output.