Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shuvoo's avatar

Multipule foraign key relation laravel mongodb

I got a Problem . I need to do has many relationship with multiple foraign and local key . I googled then i got some solition but none of work for me . maybe problem is im useing mongodb,

i also try this package awobaz/compoships not success :(

here is my code

public function getDetials()
    {

        return $this->hasMany(Transaction::class, ['UID', 'AID'],  ['UID', 'AID']);
    }
0 likes
3 replies
bobbybouwmann's avatar

I never heard of a multiple-column foreign key before... A foreign key needs to point to another table.

Maybe you can explain what you're trying to achieve with your relationship and what your data structure is?

Shuvoo's avatar
$logdata = Tracker::select('transaction_id', 'AID')->groupBy('UID', 'AID')
->with(['campaigns', 'pubs'])
->with(['pubtransaction' => function ($query) {
             $query->whereIn('AID', ['trackers.AID'])->get();
 }])->get();

but i cant excute this code .. I need to find data also where

$query->whereIn('AID', ['trackers.AID'])->get();
trackers <- this is my first table name

Tray2's avatar

It looks to me that you are trying to use a relational database structure in a non relational database. Is there a particular reason that you use MongoDB instead of MySQL or MariaDB?

Please or to participate in this conversation.