public static function updateInventory() { foreach (Bullet::all() as $bullet) { $rounds_purchased = DB::table('inventories')->where('bullet_id', $bullet->id)->sum('rounds'); $rounds_fired = DB::table('shoots')->where('bullet_id', $bullet->id)->sum('rounds'); $bullet->inventory = $rounds_purchased - $rounds_fired; $bullet->save(); } }