-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format mobile number to E164 format.
- Loading branch information
1 parent
a778afb
commit 6b05c3a
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
database/migrations/2020_05_01_142326_format mobile numbers to E164 format.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
use App\ShortenedUrl; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class FormatMobileNumbersToE164Format extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
DB::transaction(function () { | ||
ShortenedUrl::query() | ||
->with('group') | ||
->withTrashed() | ||
->chunk(1000, function ($urls) { | ||
$urls->each(function ($url) { | ||
|
||
if ($url->type === 'single') { | ||
$url->timestamps = false; | ||
|
||
$url->update([ | ||
'mobile_number' => $url->mobile_number, | ||
]); | ||
|
||
} else { | ||
$url->group->each(function ($item) { | ||
$item->timestamps = false; | ||
|
||
$item->update([ | ||
'mobile_number' => $item->mobile_number, | ||
]); | ||
}); | ||
} | ||
|
||
}); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
} | ||
} |