показывает:
Код: Выделить всё
+----+--------+
| id | show |
+----+--------+
| 1 | show1 |
| 2 | show2 |
| 3 | show3 |
+----+--------+
Код: Выделить всё
+----+--------+
| id | type |
+----+--------+
| 1 | type1 |
| 2 | type2 |
| 3 | type3 |
+----+--------+
Код: Выделить всё
+---------+---------------+
| show_id | draft_type_id |
+---------+---------------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
+---------+---------------+
Код: Выделить всё
public function draft_types()
{
return $this->belongsToMany('App\Models\DraftTypes', 'show_draft_types', 'show_id', 'draft_type_id');
}
Код: Выделить всё
Shows::where('id', 1)->with(['draft_types'])->first()
Код: Выделить всё
{
id: 1,
show: "show1",
draft_types: [
{
id: 1,
type: "type1"
},
{
id: 2,
type: "type2"
},
{
id: 3,
type: "type3"
}
]
}
Код: Выделить всё
{
id: 1,
show: "show1",
draft_types: [
"type1",
"type2",
"type3"
]
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... of-array-o
Мобильная версия