我的laravel有问题 我无法发布数据
一个错误说
InvalidArgumentException in Validator.php line 2593:
Validation rule unique requires at least 1 parameters.
这是我的代码
public function postUbah(Request $request, $id)
$validator = Validator::make($request->all(), [
'username' => 'required|unique:user|min:5',
'name' => 'required',
'group' => 'required'
]);
}
感谢您的帮助。
这是我的模特
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = 'user';
protected $fillable = ['username', 'password'];
protected $hidden = ['password', 'remember_token'];
答案 0 :(得分:2)
您忘记在验证规则中添加参数,以指定在验证规则中应该唯一的数据库表列。你可以这样做,
$validator = Validator::make($request->all(), [
'username' => 'required|unique:user,name|min:5',
'name' => 'required',
'group' => 'required'
]);
答案 1 :(得分:2)
为什么不像这样使用
L5.5
public function postUbah(Request $request, $id)
$validator = $request->validate([
'username' => 'required|unique:user|min:5',
'name' => 'required',
'group' => 'required'
]);
}
L5.4
public function postUbah(Request $request, $id)
$validator = $this->validate($request, [
'username' => 'required|unique:user|min:5',
'name' => 'required',
'group' => 'required'
]);
}
我知道您的表名是user
..请确保您的用户模型
class User {
protected $table = "user";
}