V
V
Vanya Huk2018-04-01 01:51:31
Laravel
Vanya Huk, 2018-04-01 01:51:31

How to properly build Laravel relationships?

There are 3 tables
products [ id, name, model_id]
models[id, name, brand_id]
brands[id, name]
I make a type select: Where is model - $this->belongsTo(Model::class) How can I link the table with the brand now?
Product::take(10)->with('model', 'brand')->get();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Nagorny, 2018-04-01
@vanyahuk

Product::take(10)->with('model', 'model.brand')->get();

And read everything here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question