D
D
Denis Bukreev2017-09-30 01:23:38
Laravel
Denis Bukreev, 2017-09-30 01:23:38

How to build a competent query in the database with related tables?

I thought that I would put the data in the database and it was done, but it wasn’t there - the difficulties were ahead)
I read it four times and tried to implement what was written in the English-language and Russian-language documentation, but this is beyond my understanding.
There are three tables (briefly, without extra fields):

bids
 - id
 - user_id
users
 - id
 - auto_id
autos
 - id

each bid always has one user, each user always has one auto
From the documentation, I understood that this is either a 1k1 or a polymorphic relationship.
How to make a request so that an even JSON is returned in the format (I have ajax requests):
[
 {
  id : 1,
  user : {
   id : 1,
   name: 'vanyok',
   auto : {
    id : 1,
    model: 'tesla'
   }
  }
 },
 {
  id : 2,
  user : {
   id : 5,
   name: 'sanyok',
   auto : {
    id : 7 ,
    model: 'huesla'
   }
  }
 }
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Gerasimov, 2017-09-30
@denisbookreev

In the context of laravel, it will be something like this: It remains only to build relationships https://laravel.com/docs/5.5/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question