Skip to content
Advertisement

Eloquent Relationships hasMany use loop

I have a database with multiple address records of a user. When I do “pluck()” and “join()” in the foreach path, I get results. But when I type $user->getAddress->address in structures like hasOne, I get the result I want. In short, can I return the loop in hasMany more practically?

Following my code:

user Table

JavaScript

adress Table

JavaScript

UserModel

JavaScript

Controller

JavaScript

Advertisement

Answer

You can use the Collection ‘s implode method to make it look a bit less verbose.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement