I am just very new to laravel and today I have run some code and get stuck at this code.
$topic = topic::where('id', $id)->get();
Because it's not an array. It's a collection.
You can convert it to an array with
$topic = topic::where('id', $id)->get()->toArray();