model:
return $this->belongsToMany('App\Models\OrgStructure', 'OrgStructurePost', 'post_id', 'node_id')
->withPivot('org_struct_post_id');
here is print_r() of returned collection object named as $postNodes:
[0] => ...... Object
(
[attributes:protected] => Array
(
[id] => 24
[name] => Finance
)
[original:protected] => Array
(
[id] => 24
[name] => Finance
[pivot_post_id] => 1
[pivot_node_id] => 1
[pivot_org_struct_post_id] => 1
)
)
[1] => ...... Object
(
[attributes:protected] => Array
(
[id] => 25
[name] => Admin
)
[original:protected] => Array
(
[id] => 25
[name] => Admin
[pivot_post_id] => 1
[pivot_node_id] => 2
[pivot_org_struct_post_id] => 2
)
)
I m trying to filter this collection using 'where()' method as shown below:
$currentRecord = $postNodes->where('pivot_org_struct_post_id','1')->first();
But could not access 'original:protected' array, using 'where()' method.
So how to filter above collection by key 'pivot_org_struct_post_id'?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire