提交表单后,我收到此错误“Method Illuminate \ Validation \ Validator :: validate255不存在。”,
我已经检查了我已经验证的功能,甚至找不到问题所在?
这是我的第一个商店功能:
public function store(Request $request)
{
// Validate form
$this->validate($request, [
'name' => 'required|255',
'email' => 'required|email|unique:users'
]);
// Generate password
if(Request::has('password') && !empty($request->password)){
$password = trim($request->password);
} else{
# set the manual password
$length = 10;
$keyspace = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$str = '';
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$str .= $keyspace[random_int(0, $max)];
}
$password = $str;
}
$user = new User();
// Insert User's data into database
$user->name = $request->name;
$user->email = $request->email;
$user->password = Hash::make($password);
if($user->save()){
return redirect()->route('users.show', $user->id);
} else{
Session::flash('danger', 'Sorry, a problem occured while creating this user.');
return redirect()->route('users.create');
}
}
并且,这是editinig用户的更新功能:
public function update(Request $request, $id)
{
$this->validate($request, [
'name' => 'required|max:255',
'email' => 'required|email|unique:users,email,'.$id
]);
$user = User::findOrFail($id);
$user->name = $request->name;
$user->email = $request->email;
if($request->password_options == 'auto'){
# set the manual password
$length = 10;
$keyspace = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$str = '';
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$str .= $keyspace[random_int(0, $max)];
}
$password = $str;
} elseif($request->password_options == 'manual'){
$user->password = Hash::make($request->password);
}
if($user->save()){
return redirect()->route('users.show', $id);
} else{
Session::flash('danger', 'There was a problem saving the updated user info to the database. Please, try again.');
return redirect()->route('users.edit', $id);
}
}
我不认为前端存在问题,但如果可以为某些人提供帮助,我会更新帖子。
答案 0 :(得分:1)
偶然'name' => 'required|255',
到'name' => 'required|max:255',
答案 1 :(得分:0)
您对该名称的验证存在问题。
您可以使用以下代码更改验证码。
$this->validate($request, [
'name' => 'required|max:255',
'email' => 'required|email|unique:users'
]);
您可以使用以下链接查看可用的laravel验证: https://laravel.com/docs/5.6/validation#available-validation-rules