I have 3 tables in a database
- Transaction
{'id','bill_id','remark'}
- Bills
{'id','third_party','amount'}
- ThirdParty
{'id','company_name',remark}
The 'transaction' table has column bill_id
coming from 'Bills' and Bills table has 'third_party'
column which connected to ThirdParty table column -> 'id'
So here I am trying to fetch company_name
using laravel eloquent relation
My Transaction model:
public function Bills()
{
return $this->hasOne('App\Bills','id','bill_id');
}
Bills:
public function third_party()
{
return $this->belongsTo('App\ThirdParty','third_party','id');
}
I am getting null value for company_name
Here is the query i am using
Transaction::with('Bills.third_party')->get();
And i have corrected in question (third_party_name) to company_name column name i wrote here was my old join query name which is visible in screenshot, basically i am trying to fetch company name.