Reputation: 5105
I'm currently using a form to get a phone number from the user, and they are directed to add area code but no spaces or dashes. It's validated here:
$this->validate($request, [
'phone_number' => 'digits:10'
]);
This works fine but I then need to send the phone number from the request
$sendNumber = $newCallFunction->phoneSubmission($request->phone_number);
as a string with '+' and the country code prepended to it. So in America the phone number they enter as 5555555555 should be sent in the function call as +15555555555
How should I set this properly using laravel?
Upvotes: 0
Views: 2115
Reputation: 342
I would make an associative array of the country code to the code code and then prepend that.
$countryCode = ['NL' =>'+075','US' =>'+1' ];
$sendNumber = $newCallFunction->phoneSubmission($countryCode['us' . $request->phone_number);
Depends on how you get the country tho
Upvotes: 1