How can I check if one input have integer value?
For example:
if ($request->input('public') == ¿int?){
}
How can I check if one input have integer value?
For example:
if ($request->input('public') == ¿int?){
}
You should try this:
if (is_int($request->input('public'))){
}
OR
if (is_numeric($request->input('public'))){
}
filter_var($request->input('public'), FILTER_VALIDATE_INT) !== false
because:
Use is_int
:
$number = $request->input('public');
if (is_int($number)) {
dd('number is an integer');
} else {
dd('number is not an integer');
}
Data taken from the input is always a string.
Use Laravel validation to check if the data from the input is integer or number.
You can use ctype_digit
<?php
$cadenas = array('1820.20', '10002', 'wsl!12');
foreach ($cadenas as $caso_prueba) {
if (ctype_digit($caso_prueba)) {
echo "La cadena $caso_prueba consiste completamente de dígitos.\n";
} else {
echo "La cadena $caso_prueba no consiste completamente de dígitos.\n";
}
}
?>
You can also use shorthand if:
$isInteger = (is_int($request->input('public'))) ? true : false;