Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel text area validation best practice

Tags:

php

laravel

I am not sure what kind of validation I should use for comments in E-commerce website that I am currently developing. It is not much I want to validate but I'm worried about security.

So what is the best practice?

My code now looks like this:

$this->validate($request, [
    'comment' => 'max:1000',
]);

Is it safe to leave it like that?

like image 775
Dmitry Malys Avatar asked Jan 14 '18 05:01

Dmitry Malys


People also ask

How do you validate exact words in laravel?

To get the exact words to validate you can make use of Rule::in method available with laravel. Using Rule::in method whatever the values provided by this rule has to be matched otherwise it will fail.

What methods should you implement for your custom validator laravel?

You should add all your validation logic in the passes() function. It should return true or false based on the logic you have written in the function. The message() function returns a string that specifies the error message to be displayed in case the validation fails.

How many types of validation are there in laravel?

Each form request generated by Laravel has two methods: authorize and rules .


1 Answers

It depends on your needs but I could suggest some

$this->validate($request, [
    'comment' => 'required|min:3|max:1000',
]);
like image 102
Mahdi Younesi Avatar answered Oct 03 '22 05:10

Mahdi Younesi