Closed r-shaygan closed 1 year ago
Have you tried something like $coverages->column('pivot.cost');
?
Have you tried something like
$coverages->column('pivot.cost');
?
it returns this error: Call to undefined relationship [pivot] on model [Modules\Insurance\Entities\InsuranceCoverage]
Hmm.. can't test right now. Does your model's relationship has ->withPivot ('cost')
?
On Fri, Mar 3, 2023, 09:23 r-shaygan @.***> wrote:
Have you tried something like $coverages->column('pivot.cost'); ?
it returns this error: Call to undefined relationship [pivot] on model [Modules\Insurance\Entities\InsuranceCoverage]
— Reply to this email directly, view it on GitHub https://github.com/z-song/laravel-admin/issues/5727#issuecomment-1453090328, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJJJEISUB22P2NMRJPHIYLW2GL6BANCNFSM6AAAAAAVN6I4OE . You are receiving this because you commented.Message ID: @.***>
Hmm.. can't test right now. Does your model's relationship has
->withPivot ('cost')
?
yes..
public function coverages()
{
return $this->belongsToMany(InsuranceCoverage::class,'health_coverage_proposal',
'proposal_id','coverage_id')->withPivot('cost');
}
and i don't know how to insert this pivot field either
You're right, sorry, confused relation columns with nested ones. Grid treats column names as relations if there's a dot between names like in pivot.cost
, but pivot is not a relation - hence an error.
You should treat it like JSON field / array / object on the Grid's model.
$coverages->column('pivot->cost');
-- your way to go.
You're right, sorry, confused relation columns with nested ones. Grid treats column names as relations if there's a dot between names like in
pivot.cost
, but pivot is not a relation - hence an error. You should treat it like JSON field / array / object on the Grid's model.$coverages->column('pivot->cost');
-- your way to go.
it worked.. thank you.. can you help me, with how to get pivot value from a form?
$form->multipleSelect('roles','Role')->options(Role::all()->pluck('name','id'));
in the code above we can just get the related model value.. what if it has pivot field?
there is a many-to-many relationship between coverage and proposal model.
on the proposal model , i have :
i want to access 'cost' column on ProposalController: