PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] Laravel Validation Error Message required_if not working

 February 20, 2022     laravel, laravel-5.2, laravel-validation, php     No comments   

Issue

I am validating a form using Laravel 5.2

using validation check required_if for input youtube-embed. validation takes place successfully but the custom error message does not work. Here is the code maybe some one can take a look.

$messages = [
        'youtube-embed.required_if' => 'Please paste in your youtube embed code',
    ];

$this->validate($request, [
        'youtube-embed'      => 'required_if:youtube,on',
    ]);

This is the error message that laravel is returning instead of my custom error:

The youtube-embed field is required when youtube is on.

Solution

Try this:

$this->validate($request, 
    ['youtube-embed'      => 'required_if:youtube,on',], 
    ['required_if' => 'Please paste in your youtube embed code',]
);

Basically you can pass your custom messages as third parameter in validate function.



Answered By - Can Celik
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing