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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -