J
J
jazzus2019-01-12 03:39:06
Laravel
jazzus, 2019-01-12 03:39:06

How to bypass intermediate table in hasOne?

Created a UserModeration model with fields

id
user_id (User model)
status_id (Status model)
comment (Moderator comment)
moderator_id (User model)

I want to do $user->status()->name with connection via UserModeration. Those. connect the User model to the Status via UserModeration and get Kolya->active. At the same time, ManyToMany will not work. hasOne. What is the best way to do this? Does Laravel have its own way for HasOne? type hasOneThrough
You can not read:
In the docks, this is possible for ManyToMany relationships, but here hasOne turns out (the user has one UserModeration model). How to use intermediate tables for hasOne?
You can, of course, write your own method for a relation, but suddenly Laravel has its own way for hasOne as well as for many to many

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-03-09
@jazzus

hasOneThrough was added in version 5.8.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question