M
M
Morfeey2018-11-15 11:44:22
Laravel
Morfeey, 2018-11-15 11:44:22

How to get related tables?

There is a project in which there are 3 tables in the database, users, a list of sites and a table containing a list of sites associated with users. How to get a list of sites from the user model?
//tables: users, sites, site_user

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pushkarev, 2018-11-15
@AXP-dev

User::find($userId)->sites();
But the links in the models must be spelled out

A
Arthur, 2018-11-17
@ART_CORP

https://laravel.com/docs/5.7/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question