A
A
andrew-corput2018-07-31 17:38:12
Laravel
andrew-corput, 2018-07-31 17:38:12

How to make a connection?

Lot table: id, brand_id, model_id

Brand table: id, name

Models table: id, model_id, brand_id, name

I'm trying to get the model that matches the brand_id and model_id of the lot table.
in lot model
public function brand() {
        return $this->belongsTo(Brand::class, 'brand_id');
    }
    public function models() {
        return $this->hasMany(Models::class, 'brand_id', 'brand_id');
    }

in view
{{$lot->brand->name}} //отображается название бренда
    {{$lot->models}}

I get a list of models with the correct brand_id ratio,
how to add a match model_id = model_id of the lots table
I read the documentation, did not get it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-07-31
@Sanasol

So why are you linking the lot with models through the brand?
model_id is in any case unique for the brand and associated with the brand
. What kind of nonsense is the model_id field in models? They already have their own ID, so connect with it.
Those. write models.id to the lot, but not models.model_id. Some kind of porridge

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question