I have 2 models DfpLineItem and DfpCreative
DfpLineItem model with relationship
public function creatives()
{
return $this->belongsToMany('App\DfpCreative', 'dfp_licas', 'line_item_id', 'creative_id')
->withPivot('lica_data')
->withTimestamps();
}
As you see this means pivot table is dfp_licas which already exists, also there is a timestamps columns and lica_data columns.
Everything is fine with this part. When I'm trying to get the data from DfpLineItem model, everything is fine and working as expected. For example
$lineItemData = DfpLineItem::findOrFail($id); related Creatives exists in this query result and I can access to them like $lineItemData->creatives.
Problem appears, when I'm trying to use inverse relationship. Here is my is the relationship defined in my DfpCreative model
public function lineItems()
{
return $this->belongsToMany('App\DfpLineItem', 'dfp_licas', 'creative_id', 'line_item_id')
->withPivot('lica_data')
->withTimestamps();
}
I think everything is find with this relationship, but when I'm trying to get data like below Id is hardcoded
$orderData = DfpCreative::findOrFail(72174072858);
dd($orderData->lineItems);
Getting empty results, but checked many times, records exists in my dfp_licas table. No Idea why this is happening.
Any help will appreciated.
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire