If you want to multilingualize validation messages (this time in Japanese),
/resources/lang/ja/validation.php
In the attributes array of the above files field name =>Japanese name
The field name is translated into Japanese, but
How can I tell if different models use the same field name?
For example,
The User model has a name field meaning username
and
The Shop model has a name field meaning store name
.
ValidatesRequests::validate
attribute naming is
class UsersController extensions Controller
{
public function post(Request$request)
{
$this->validate($request,[
'name' = > 'required',
], null, [
'name' = > 'username',
]);
}
}
You can also specify it as shown in .
You can do it by creating validators for each.
class UsersController extensions Controller {
public function post(){
$validator=Validator::make($request->all(),[
'name' = > 'required',
]);
$validator->setAttributeNames([]
'name' = > 'username',
]);
if($validator->fails()){
return redirect ('users/')
- > with Errors ($validator)
->withInput();
}
}
}
class ShopsController extensions Controller {
public function post(){
$validator=Validator::make($request->all(),[
'name' = > 'required',
]);
$validator->setAttributeNames([]
'name' = > 'Store name',
]);
if($validator->fails()){
return redirect ('shops/')
- > with Errors ($validator)
->withInput();
}
}
}
Also, if you have created a request and are validating it,
The attributes()
method is available.
class UsersRequest extensions FormRequest {
//...
public function attributes() {
return [
'name' = > 'username',
];
}
}
© 2024 OneMinuteCode. All rights reserved.