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
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 :)
<?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();
@abusalameh thank you so much for you help ,
will give it try the back to you ,,,
thanks pro,
it work's bro ,
thanks so much
sir above solution will be written in the controller or Model?
Please or to participate in this conversation.