Answer the question
In order to leave comments, you need to log in
Why doesn't laravel see my validation error message?
Here is such a class:
<?php
namespace App\Rules;
use App\Inspections\Spam;
use Illuminate\Contracts\Validation\Rule;
class SpamFree implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
try{
return ! resolve(Spam::class)->detect($value);
} catch(\Exception $e) {
return false;
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Custom msg.';
}
}
\Validator::extend('spamfree', 'App\Rules\[email protected]');
this->validate(request(), ['body' => 'required|spamfree']);
'spamfree' => 'Custom msg',
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question