How can i compare IP submit by Form with IP range in my database (postgresql) ?
Actually my IP Range are stored in jsonb in database
$builder
->add('firstIpAddresses', TextType::class, [
'constraints' => [
new Ip([
'version' => Ip::V4_ONLY_PUBLIC
]),
],
])
->add('lastIpAddresses', TextType::class, [
'constraints' => [
new Ip([
'version' => Ip::V4_ONLY_PUBLIC
]),
],
]);
(The data transform)
/**
* From the Form to the Database
*
* @param mixed $value
* @return array|string[]
*/
public function reverseTransform($value) : array
{
$toJsonEncode = [];
if ( is_array($value) && ! empty($value) ) {
foreach ($value as $key => $val) {
$toJsonEncode[] = [
'start' => $val['firstIpAddresses'],
'end' => $val['lastIpAddresses'],
];
}
}
return $toJsonEncode;
}
(This is the IP range in database)
[{"end": "100.100.100.130", "start": "100.100.100.120"}]
If the IP is not in the range on the IP in the database so it will add the new IP else it will put error message
(Sorry for my bad english, I'm new developper and this is my first post on stackoverflow)