F
F
fiter2017-06-01 20:28:58
Laravel
fiter, 2017-06-01 20:28:58

Laravel 5.4 how to modify an Eloquent object when a query is executed?

There are User and Field models, the hasMany relationship (a user can have many fields)
Field has Name and Value fields (for example, first_name and Vasya) In this case, the $user->first_name property should appear (or $user->fields->first_name, it doesn't matter) If you make a request users()->with('fields')->get(), then the user gets the fields property , but it has a simple array, but it doesn’t suit me, I need at least an associative one with keys by Name

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nurlan, 2017-06-01
@fiter

When creating a connection , you should already have:
$user->fields->first_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question