• 14

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Laravel custom validation message parameter

I'm using laravel 5.1. I have a summernotejs form element. I've created a custom validation rule successfully, which takes the HTML provided from the form input, strips the tags, and does a strlen() call on the text content. Therefore I can see the length of a message without any tags in it.

This is my validation rule:

Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) {
    return strlen(strip_tags($value)) >= $parameters[0];

I call the validation rule by specifying: strip_min:10 or strip_min:20 etc, with the number being the minimum string length after stripping tags.

I want to add a custom message, saying that the content lengths needs to be a minimum of n characters long.

The Laravel documentation on this aspect is useless. I've opened my validation.php file, which contains all the error messages.

I've added the key strip_min to the message array, with the message: The :attribute must be at least :min characters.

When I test it, I get the error message:

The notice must be at least :min characters.

How can I convert :min into the number specified in the validation rule?! I've read the documentation but it's all over the place, and I cant understand how to just simply replace :min with the given number.

Found out.

Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) {

    $validator->addReplacer('strip_min', function($message, $attribute, $rule, $parameters){
        return str_replace([':min'], $parameters, $message);

    return strlen(strip_tags($value)) >= $parameters[0];
  • 15
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions