Answer the question
In order to leave comments, you need to log in
Laravel how to override object property?
There is this simple code:
$offer = Offer::with([
'countries' => function ($query) {
$query->select('offer_countries.id', 'offer_countries.abbr');
}
])->findOrFail($id);
$offer->countries = $offer->countries->map(function($country) {
return $country->id;
});
return $offer;
Answer the question
In order to leave comments, you need to log in
dump() before and after map?
Is it really unchanged?
maybe there is something wrong after the return?
map can be changed to:$offer->countries->pluck('id');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question