php - Laravel: a model that belongs to two other models -
in laravel, there way list of objects belong 2 models?
for example,
model transactions: belongs users belongs category
model user: has many transactions
model category: has many transactions
assuming these relationships correctly defined, kind of query make in, controller, access set of transactions belongs user x , category y?
assuming transaction table has foreign keys user_id , category_id, do:
$transactions = transaction::where('user_id', '=', 'x') ->where('category_id ', '=', 'y') ->get();
Comments
Post a Comment