Comments (8)
Are you sure nothing else has changed?
The debug screenshots of RawPhoneNumberCast
point to the second case of the validation test:
['phone', '12345', 'min']
When running the following on a fresh Laravel instance, validation fails as expected:
validator(['phone' => '12345'], ['phone' => 'phone:BR'])->passes() // false
So in fact value 12345
should never have ended up in a model and hence never even invoke RawPhoneNumberCast
...
I'm afraid the package works as designed and the root cause has to be found elsewhere... (Livewire? A controller? ...?)
from laravel-phone.
Are you sure nothing else has changed? The debug screenshots of
RawPhoneNumberCast
point to the second case of the validation test:['phone', '12345', 'min']
When running the following on a fresh Laravel instance, validation fails as expected:
validator(['phone' => '12345'], ['phone' => 'phone:BR'])->passes() // false
So in fact value
12345
should never have ended up in a model and hence never even invokeRawPhoneNumberCast
...I'm afraid the package works as designed and the root cause has to be found elsewhere... (Livewire? A controller? ...?)
Hey! Thanks for your answer.
Nothing has changed other than updating the app to Laravel 10 prefixing Laravel Phone version 5.0.3. The application is made up of the TALL Stack, using Livewire to componetize parts of the system.
Tests work fine in Laravel 9.
After updating, I had done manual tests (QA) and realized that when entering a wrong value (from the country code) manually, let's say in an input, it gives the same error. I will update the app again today and post more information.
Tonight.
from laravel-phone.
Here is the demonstration: https://www.loom.com/share/9485e579382a48f5aea9f05807c601ae
I think there is some bug with the code, or you think I'm doing something wrong according to the video?
I also tried a different approach but I got the same error:
- Remove the Laravel Phone
- Upgrade Laravel to V10
- Install Laravel Phone
... Same error!
from laravel-phone.
I was not able to understand the reason, but I found a possible fix:
The getPossibleCountries
always returns as BR
even the number is something like: 12345 - that's the correct behavior.
The fix can be something like this:
from laravel-phone.
Thanks for the investigation. It clearly points out that there's a breaking change I forgot to mention in the release notes.
I'm not tempted to "fix" this scenario though. When using RawPhoneNumberCast
you should ensure that only valid phone numbers make it into the model. Otherwise the cast will never be able to return a usable phone object when accessing the attribute. In v4 the cast gracefully returned an invalid phone object and that's why your tests passed, but now in v5 that behavior is aligned with E164PhoneNumberCast
and it'll only accept valid phone numbers in order to avoid unexpected stuff later down the line.
So I think the way forward is to check how it's possible that the invalid value ends up in the model, and then prevent that.
from laravel-phone.
Thanks for the investigation. It clearly points out that there's a breaking change I forgot to mention in the release notes.
I'm not tempted to "fix" this scenario though. When using
RawPhoneNumberCast
you should ensure that only valid phone numbers make it into the model. Otherwise the cast will never be able to return a usable phone object when accessing the attribute. In v4 the cast gracefully returned an invalid phone object and that's why your tests passed, but now in v5 that behavior is aligned withE164PhoneNumberCast
and it'll only accept valid phone numbers in order to avoid unexpected stuff later down the line.So I think the way forward is to check how it's possible that the invalid value ends up in the model, and then prevent that.
Sorry, but that doesn't make sense to me. How do you explain the fact that the getPossibleCountries
method always returns a valid country even if the getCountry()
method of the PhoneNumber
class returns null? In my tests, even for phones like (11) 91234 the getPossibleCountries
method was able to work correctly detected that the phone is from Brazil.
from laravel-phone.
Thanks for the investigation. It clearly points out that there's a breaking change I forgot to mention in the release notes.
I'm not tempted to "fix" this scenario though. When using
RawPhoneNumberCast
you should ensure that only valid phone numbers make it into the model. Otherwise the cast will never be able to return a usable phone object when accessing the attribute. In v4 the cast gracefully returned an invalid phone object and that's why your tests passed, but now in v5 that behavior is aligned withE164PhoneNumberCast
and it'll only accept valid phone numbers in order to avoid unexpected stuff later down the line.So I think the way forward is to check how it's possible that the invalid value ends up in the model, and then prevent that.
"When using RawPhoneNumberCast
you should ensure that only valid phone numbers make it into the model": in this test I'm creating contacts with valid phone numbers (via Faker) and after that I just try to change them with wrong numbers and this is where the problems occur.
from laravel-phone.
Sorry, but that doesn't make sense to me. How do you explain the fact that the
getPossibleCountries
method always returns a valid country even if thegetCountry()
method of thePhoneNumber
class returns null? In my tests, even for phones like [(11) 91234](tel:(11) 91234) thegetPossibleCountries
method was able to work correctly detected that the phone is from Brazil.
It doesn't. That method solely exists to provide input for constructing a new phone object. It simply returns the parameters you hardcoded provide to the cast. "Coincidently" your test cases are Brazilian numbers and your cast parameter is BR.
$casts = [
'phone' => RawPhoneNumberCast::class . ':BR',
];
so in case of an invalid (or any) number the cast attempts the following:
new PhoneNumber('12345', 'BR')
...and hence getCountry()
returns null because in this particular example the construction leads to an invalid state.
from laravel-phone.
Related Issues (20)
- How to only accept international format (E.164) for a specific country? HOT 2
- GH valid phone number starting with 025xxxxxxx fails validation, however 0256 works
- Validator fails on empty phone field, when required_if is present HOT 3
- Validation for Lebanese mobile numbers starting with 78 fails HOT 1
- When I used it, I found that the getCountryCode method was missing HOT 1
- Documented formatE164 method does not return expected result HOT 1
- Validation Message HOT 1
- how do i use AUTO with the class interface? HOT 1
- Failed to open stream: No such file or directory in /propaganistas/laravel-phone/src/Concerns/PhoneNumberFormat.php HOT 3
- "mobile" parameter no longer working in 5.1.0 when one of the data fields is "mobile" HOT 2
- Support for Laravel 11 HOT 1
- Laravel-Intl is unavailable HOT 2
- Simple phone validation fails
- Laravel tripping the + HOT 4
- Nullable rule doesn't work at request validation. HOT 1
- phone:INTERNATIONAL rule stopped working HOT 2
- Not a bug but feature request - expose the isPossibleNumberWithReason HOT 1
- Invalid number format passes validation HOT 1
- Custom validation messages for different phone types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-phone.