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

boyjarv's avatar

Add in a new table into my query

Hi,

In my payments model I have created a relationship belongsTo for my donate_messages table on payment.id

I would now like to bring through 'MESSAGE' into the Payment query below

Thanks

$query = Payment::whereIn('type', ['subscription', 'purchase'])->where('campaign_id', '=', $campaign_id)->active();
0 likes
5 replies
Sinnbeck's avatar

How do you want it in there? Do you mean you wish to load the relationship? Or restrict the results by the relationship?

boyjarv's avatar

I have tried passing in:

->with('message')
Sinnbeck's avatar

That sounds correct. And the problem with that is?

boyjarv's avatar

I just want to load in the relationship into payments so the message object from the donation_message table will be available on payment.id

Please or to participate in this conversation.