where(['puid' => 0]) ->get(); foreach ($result as $item) { DB::table('promotions') ->where('id', $item->id) ->update([ 'puid' => DB::table('users')->where('id', $item->uid)->value('pid') ]); } } }