When I use Laravel's string validation rule, what exactly is it doing? For example, does it simply run php's is_string() method, or does it run filter_var() perhaps, with the FILTER_VALIDATE_REGEXP constant?
Secondly, how do I strip tags using Laravel?
When you use Laravel's string validation, the following function gets called
protected function validateAttribute($attribute, $rule) { ... }
which you could find in
vendor/laravel/framework/src/Illuminate/Validation/Validator.php
and if you examine the method, you'll find this piece of code
$method = "validate{$rule}";
if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) {
$this->addFailure($attribute, $rule, $parameters);
}
which would call the trait Concerns\ValidatesAttributes
/**
* Validate that an attribute is a string.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function validateString($attribute, $value)
{
return is_string($value);
}
and to strip tags you could use PHP's strip_tags method
When I use Laravel's string validation rule, what exactly is it doing?
When you use Laravel's string validation rule, it only checks if the field under validation is of string type or not.
https://laravel.com/docs/5.0/validation#rule-string
how do I strip tags using Laravel?
You can use the strip_tags() function:
http://php.net/manual/en/function.strip-tags.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With