L
L
lynnikvadim2016-07-27 23:31:31
Laravel
lynnikvadim, 2016-07-27 23:31:31

Table relationships in Laravel?

There is a table with records.
There is a table with users.
There is a table with categories for entries.
There are two more pivot tables.
In one I write the relationship of users and records.
In another relationship records and categories.
How do I get all the posts of a user and the categories of those posts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2016-07-27
@lynnikvadim

0) Set up links
1) User::with('posts.categories')->get()

A
Anton, 2016-07-28
@Yadalay

Use hasOne() or hasMany() for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question