我基本上不想使用 Laravel 基于所有模型的属性创建一个表,但问题是,该方法getAttributes()会忽略我自定义添加的访问器,即使我已将属性的名称添加到属性中$appends(将其添加到json 和数组转换)。但我仍然无法获得我的自定义属性。有任何想法吗?
好的,我在这里遇到了一个非常困难的情况,我想我要么错过了一些已经存在的重要东西,要么 Laravel 没有提供一种方法来实现这一点。我想用我想在消息中替换的自定义占位符指定自定义验证错误消息。问题在于:我正在使用Laravel 文档明确指出的regex验证规则,应该更好地将其传递给数组以避免不必要的分隔符行为。情况如下:我想指定一个用于验证的全局多语言消息,我已经这样做了:name.regex
'custom' => [
'name' => [
'regex' => 'The :attribute must corespond to the given format: :format!'
]
]
Run Code Online (Sandbox Code Playgroud)
如您所见,我:format在该消息中放置了一个自定义占位符,因为对于name不同类的属性,我将匹配不同的正则表达式。所以我希望能够在验证过程中输入每个给定正则表达式的自定义人类可读描述(作为参数)。所以我在我的控制器中执行以下操作:
$input = Input::all();
$validator = Validator::make($input, [
'name' => ['required', 'regex:/^\p{Lu}\p{L}+ \p{Lu}\p{L}+$/u']
]);
Run Code Online (Sandbox Code Playgroud)
我还有一个Validator::replacer()方法AppServiceProvider.php可以替换:format消息中的占位符:
Validator::replacer('regex', function($message, $attr, $rule, $parameters){
return str_replace(':format', "I would like to be able to somehow retrieve the custom format description here, but using \$parameters[] is not an …Run Code Online (Sandbox Code Playgroud)