Craft 3 - How do you programatically update a field type that is a Category?
You should insert an array of ids - not an array of elements - in order to make it work. That's basically it

$new_$nearby_locations[] = $nearby_location-&gt;id;


(that's usually better than array push too)

Edit

But your error message sounds more like your slug is an Array or something like this. Do you change any other fields somewhere?