Level 53
If youre using laravel 5.5 you van do this:
$users->each->append('links');
9 likes
Hi Guys, I want to add an attribute to Model only when I called id when I append it to the array always return attribute but I want only when called it returning.
//User Model
public function getLinksAttribute()
{
return [
'equipment_url' => route('profile', $this->id),
];
}
//User Controller
$users = Users::get();
foreach($users as $user) {
$user->append('links');
}
I want to remove foreach and call links on $users instead of each $user.
Please or to participate in this conversation.