mercredi 21 novembre 2018

How get relation with pivot table?

I have a tables:

categories - this is vehicle categories

enter image description here

dicts_groups - i have a lot of things there

enter image description here

dicts - for my dict groups i see what is body type(s)

enter image description here

category_dict_group - pivot table

enter image description here

My category class

public function bodyTypes()
    {
        return $this->belongsToMany('App\DictGroup');
    }

this is my dictGroup class

public function dicts() {
        return $this->belongsTo('App\Dict');
   }

I want get all body parts for category = 1 so my code is simple now:

dd(Category::find(1)->bodyTypes()->pluck('id'));

result is

Collection {#248 ▼
  #items: array:1 [▼
    0 => 7
  ]
}

which is ok cause 7 is my dict_group_id from pivot table i think. How can i get body type list from dict ? like what i need add to function bodyTypes to get list like from table DICTS (id, symbol, public_name)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire