【问题标题】:laravel change validation default message from front sidelaravel 更改来自前端的验证默认消息
【发布时间】:2021-12-02 17:18:32
【问题描述】:

Laravel 更改验证默认消息

  • 从前端更改验证消息
  • 读取validation.php 文件,然后从前端写入该文件

有可能吗?

【问题讨论】:

  • from front side 是什么意思?
  • 是的,这是可能的。但我认为这不是一个合适的问题。
  • 在 Stackoverflow 上,我们希望您在提问之前进行适当的研究。在文档中,您有很多选项可以自定义验证消息laravel.com/docs/8.x/validation

标签: php laravel laravel-validation


【解决方案1】:

使用验证器类

use Illuminate\Support\Facades\Validator;

$rules = [
    'name' => 'required',
    'email' => 'required|email,
];

$messages = [
    'name.required' => 'The :attribute is required',
    'email.required' => 'The :attribute is required',
    'email.email' => 'The :attribute is not valid',
];

$validator = Validator::make($request->all(), $rules, $messages);

if ($validator->fails()) {
    return Redirect::back()->withErrors($validator)->withInput();
} else {
  `enter code here`
}

【讨论】:

    猜你喜欢
    • 2018-06-21
    • 1970-01-01
    • 2020-08-15
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    相关资源
    最近更新 更多