From be0e327221a07cd978873cd2590eceb09593a79e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 23 Oct 2020 14:14:34 -0700 Subject: [PATCH] Simplified the migration --- ...3_161736_fix_zero_values_for_locations.php | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/database/migrations/2020_10_23_161736_fix_zero_values_for_locations.php b/database/migrations/2020_10_23_161736_fix_zero_values_for_locations.php index 477587d71d..20a222496a 100644 --- a/database/migrations/2020_10_23_161736_fix_zero_values_for_locations.php +++ b/database/migrations/2020_10_23_161736_fix_zero_values_for_locations.php @@ -15,30 +15,15 @@ class FixZeroValuesForLocations extends Migration */ public function up() { - $assets = Asset::where('location_id', '=', '0')->orWhere('rtd_location_id', '=', '0')->get(); - $users = User::where('location_id', '=', '0')->get(); + App\Models\Asset::where('location_id', '=', '0') + ->update(['location_id' => null]); - foreach ($assets as $asset) { + App\Models\Asset::where('rtd_location_id', '=', '0') + ->update(['rtd_location_id' => null]); - if ($asset->location_id == '0') { - $asset->location_id = ''; - } + App\Models\User::where('location_id', '0') + ->update(['location_id' => null]); - if ($asset->rtd_location_id == '0') { - $asset->rtd_location_id = ''; - } - - $asset->save(); - - } - - foreach ($users as $user) { - if ($user->location_id == '0') { - $user->location_id = ''; - } - - $user->save(); - } } /**