A
A
amorphine2016-08-02 15:55:29
Laravel
amorphine, 2016-08-02 15:55:29

How to construct a query in which leftJoin should take the name of the second table from the cell of the first?

There is a pivot table of products from which we select id, table values.
Product details are stored in tables whose names are stored in the summary in the table field.
There is a task to choose products of a certain brand.
The beginning looks like this

$productsQuery = \Db::table('im_depend');
//нужны продукты только со статусом ниже 3.
$brand_products=$productsQuery->where('.status', '<', 3)
                ->select('id', 'table')
      ?????????????????
                ->where('brand', '=', $brand)->get();

Now the problem itself is to make the join so that it uses the table value, from which it will take the name of the table. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Koryukov, 2016-08-02
@amorphine

I doubt that it is generally possible in one query to use the data stored in the table as the name of the database objects.
Most likely, you will have to make additional queries, ideally one for each product table.
In general, things like goods should be stored using the EAV structure.

A
Alexander Gavva, 2016-08-05
@aprel_co

It is better to change the tags for the question, post a dump of the tables.
The problem is to understand what kind of request you need to write in general, and how to arrange it in Laravel is the tenth thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question