Я пытаюсь объединить 3 таблицы: - customer, customer_item и items.
- покупатель - данные покупателя
- товары - подробности товара
- customer_item - отношение покупателя к товарам
покупатель - модель
public function itemRel(){
return $this->hasMany(CustomerItem::class,'customer_id');
}
CustomerItem - модель
public function itemDetails(){
return $this->hasOne(Items::class, 'id');
}
CustomerController
$customer = Customers::find($id);
$data = $customer->itemRel();
return $data;
Структура схемы
customer - [id,name,mobile,username...]
items - [id, item_name, quantity, nature ....]
customer_item - [id, customer_id,item_id...]
Я хочу перечислить все элементы, связанные спользователь (customer_item)