Laravel validation


In Laravel i’m trying to validate a text field to allow only a certain number of words. For what I know there is no validation of the number of words in Laravel so i’m doing it like this, but having some problems displaying the error. Using laravel 5.4. Thanks

$rules = [
                'title' => 'required|max:40',
                'description' => 'required',
                'deadline_date' => 'required'

            $description = Input::get('description');
            if(count(explode(' ', $description)) > 5)
                $rules['description'] = 'maxWords';

$this->validate($request, $rules, [
                'description.required' => 'a description is required',
                'description.maxWords' => 'max words reached'

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.