Как я могу получить некоторые данные из 3 таблиц, используя eloquent в laravel 5?У меня есть 3 таблицы, Списки, Карта, Пользователь
Список моделей
public function card()
{
return $this->hasMany(Card::class);
}
Модель карты
public function lists()
{
return $this->belongsTo(Lists::class);
}
public function member()
{
return $this->belongsToMany(User::class)->withPivot('status','user_role')->withTimestamps();
}
Модель пользователя
public function card_member(){
return $this->belongsToMany(Card::class)->withTimestamps();
}
Iхотите получить список в карточке, который назначается конкретному пользователю (пример user_id: 2)
Пример: данные JSOn
{
"id": 2,
"boards_id": "1",
"list_name": "List 2 B1 U1",
"position": 2,
"created_at": "2019-04-03 16:02:03",
"updated_at": "2019-04-03 16:02:03",
"card": [
{
"id": 8,
"lists_id": "2",
"card_title": "Card 3 L2",
"labels": null,
"description": null,
"start_card": null,
"end_card": null,
"position": 2,
"is_archieved": false,
"created_at": "2019-04-26 15:34:22",
"updated_at": "2019-04-26 15:34:22"
},
{
"id": 9,
"lists_id": "2",
"card_title": "Card 4 L2",
"labels": null,
"description": null,
"start_card": null,
"end_card": null,
"position": 3,
"is_archieved": false,
"created_at": "2019-04-26 15:34:25",
"updated_at": "2019-04-26 15:34:25"
}
Структура таблицы: Списки:
id
boards_id
listname
position
Карта:
id
lists_id
card_title
Card_user (сводная таблица):
id
card_id
user_id