T
T
ThreegunD2017-03-28 15:47:17
Laravel
ThreegunD, 2017-03-28 15:47:17

Many-to-many relationships, get data not related to relationship?

cca16dd7e0744c5584f5bd498b48dfa8.png
There is such a connection in the database.
Connected them through belongsToMany.
I get the result $products = User::find(Auth::id())->products()->get();
Actually, is it possible to modify this query to have the "count" property from the link table? To get it like this:
foreach ($products as $product)
$product->name //product name (works)
$product->price //price (works out)
$product->count //quantity in a basket (somehow it is necessary to receive)
PS Or the linking table should not have additional. properties and you need to remove the "count" column, make a separate table with the "count" column and link it one-to-one with the connecting users and products?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question