Answer the question
In order to leave comments, you need to log in
How to use pluck() at the request level?
Given:
- laravel 5.6
- a model (let's call it A) with a hasMany relationship (let's call it B) to another model. Which has a column structure - id | a_id | key | value
Problem:
Need to retrieve data along with related data via hasMany. And here the problem is that the data received through the connection must first be passed through pluck('value', 'key').
I make the request like this:
$a = A::with('B')->get();
dd($a);
public function B()
{
return $this->hasMany(B::class);
}
Answer the question
In order to leave comments, you need to log in
This cannot be done not only technically, but also in meaning - there must be models on both sides of the relationship.
You need to add the necessary fields to the selection and "after receiving, twist them in a cycle."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question