-1

I am using Laravel 8. I have 3 tables users, campaigns and payments

User has many Campaigns and Campaign has many payments table Payments has campaign_id and table campaigns has user_id

I want to fetch auth user payment details but table payments does not consist user_id but campaign_id.

How do I get these details?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41

1 Answers1

0

your query is so simple if you are using eloquent eelationships try this line of code

\Auth::user()->campaigns()->payments();

if you want to do that manualy

User::query()
                ->join('campaigns c' , 'c.user_id' , '=' , 'users.id')
                ->join('payments p' , 'p.campaign_id ' , '=' , 'c.payment_id')
                ->get(['p.*']);
Ayoub ait
  • 163
  • 2
  • 4