Loach's avatar
Level 11

Is there a better way to do this

I am getting a comma separated string

$user = User::where('id',\Auth::user()->id)->with(['influences'])->first();
        $influencesArray = array();
        foreach($user->influences as $influence){
            $influencesArray[] = $influence->name;
}
        
        $influencesString = implode(",", $influencesArray);
0 likes
4 replies
Loach's avatar
Level 11

I get this error. I am trying to just get the name from the influences relation. I think it is an array.

Column not found: 1054 Unknown column 'influences' in 'field list' (SQL: select `influences` from `users`
Tray2's avatar
Tray2
Best Answer
Level 74

My bad try this instead

$influences = $user->influences->implode('name', ',');

Please or to participate in this conversation.