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

amrsoft's avatar

Laravel how to select from 3 different tables

Hello , actually i don't know how to explain my problem but i have 3 tables

invoices , banks , currencies

invoice table fields

------------------------------
| - id                  |
| - bank_id         |
| - cash                |
------------------------------

banks table fields

------------------------------
| - id                  |
| - bank_name           |
| - currency_id     |
------------------------------

currencies table fields

------------------------------
| - id                  |
| - bank_id         |
| - currency_symbols    |
------------------------------

what i need to select

invoice.id , banks.bank_name , currencies.currency_symbols

any way to join this 3 tables in one query ?

thanks

0 likes
6 replies
abusalameh's avatar
select invoice.id , bank.bank_name, currencies.currency_symbols

from invoice 

join banks 
on invoice.bank_id = banks.id

join currencies 
on currencies.id = banks.currency_id and currencies.bank_id = banks.id 

this is the sql I'll write you the Model version :)

abusalameh's avatar
Level 30
<?php 
use DB;

$users = DB::table('invoices')
            ->join('banks', 'invoice.bank_id ', '=', 'banks.id')
        ->join('currencies', function ($join) {
                $join->on('currencies.id', '=', 'banks.currency_id')
                 ->on('currencies.bank_id','=','banks.id ');
             })
            ->select('invoice.id' , 'bank.bank_name', 'currencies.currency_symbols')
            ->get();
3 likes
amrsoft's avatar

@abusalameh thank you so much for you help ,

will give it try the back to you ,,,

thanks pro,

1 like
bernardkortor's avatar

sir above solution will be written in the controller or Model?

Please or to participate in this conversation.