I have a table with description column. Description has a datatype text (but I tried to change to longText type into phpmyadmin). I have a validation rule too:
public function rules()
{
return [
'title' => 'required|string|between:6,50',
'city' => 'required|integer|exists:cities,id',
'phone' => 'required_without:mail|digits:9',
'mail' => 'nullable|required_without:phone|email',
'description' => 'required|string|between:30,600',
'file' => 'nullable|mimes:jpeg,jpg,png|max:3000'
];
}
And it works but the problem is that if I write a very long text, I don’t receive any error instead just refresh only. I had the same with other controllers method. How I can I solve my problem?
2
Answers
When you already made a rule, and validate it in Controller, you need to make condition if the validator fails, you need to return the error to the view. You can follow code below
After that check the validator with
In your view, just show the error with
The page refreshes because of the form’s submission.
As for the validation check,
There are 3 main types of validation –
1. Browser validation
2. Front-end validation
3. Server-side validation
The errors that you have seen in other fields of the form are probably because of the Browser validation. It’s built into the browser.
However, with your current implementation, it is Server-side validation.
It will work on the background, but will not show in the front end.
For that, please add the following code inside the body of your html page.
Also please add the following function to your validatior’s Request class.