我尝试为两列设置唯一的验证,一个是 BadgeCode ,另一个是 Tazkera ,但是出现以下错误,但对于其余的列,该验证可以正常工作:
错误:
方法Illuminate \ Validation \ Validator :: validateTazker不存在。
方法Illuminate \ Validation \ Validator :: validateBadgeCode不存在。
迁移代码适用于员工表:
public function up()
{
Schema::create('employees', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('BadgeCode')->unique();
$table->string('BadgeType');
$table->integer('company_id');
$table->integer('nationality_id');
$table->string('lastname');
$table->string('firstname');
$table->string('tazker')->unique();
$table->string('telphonenumber');
$table->string('position');
$table->string('supervisorname');
$table->string('supervisornumber');
$table->string('issuedate');
$table->string('expiredate');
$table->string('serialnumber')->default('000000');
// $table->boolean('checkout')->default(0);
$table->softDeletes();
$table->timestamps();
});
}
我的控制器代码为:
public function store(Request $request)
{
$this->validate($request,[
'BadgeCode'=>'required|string|BadgeCode|unique:employees',
'BadgeType'=>'required',
'company_id'=>'required',
'nationality_id'=>'required',
'lastname'=>'required',
'firstname'=>'required',
'tazker'=>'required|string|tazker|unique:employees',
'telphonenumber'=>'required',
'position'=>'required',
'supervisorname'=>'required',
'supervisornumber'=>'required',
'issuedate'=>'required',
'expiredate'=>'required',
'serialnumber'=>'required'
]);
return Employee::create([
'BadgeCode'=>$request['BadgeCode'],
'BadgeType'=>$request['BadgeType'],
'company_id'=>$request['company_id'],
'nationality_id'=>$request['nationality_id'],
'lastname'=>$request['lastname'],
'firstname'=>$request['firstname'],
'telphonenumber'=>$request['telphonenumber'],
'position'=>$request['position'],
'supervisorname'=>$request['supervisorname'],
'supervisornumber'=>$request['supervisornumber'],
'issuedate'=>$request['issuedate'],
'tazker'=>$request['tazker'],
'expiredate'=>$request['expiredate'],
'serialnumber'=>$request['serialnumber'],
]);
}
Employees.vue中的HTML代码是
<div class="form-group">
<input v-model="form.BadgeCode" placeholder="Enter BadgeCode" type="text" name="BadgeCode" class="form-control" :class="{ 'is-invalid': form.errors.has('BadgeCode') }" />
<has-error :form="form" field="BadgeCode"></has-error>
</div>
<div class="form-group">
<input v-model="form.tazker" placeholder="Enter tazker" type="text" name="tazker" class="form-control" :class="{ 'is-invalid': form.errors.has('tazker') }" />
<has-error :form="form" field="tazker"></has-error>
</div>
答案 0 :(得分:1)
删除BadgeCode验证属性
$this->validate($request,[
'BadgeCode'=>'required|string|unique:employees',
'BadgeType'=>'required',
'company_id'=>'required',
'nationality_id'=>'required',
'lastname'=>'required',
'firstname'=>'required',
'tazker'=>'required|string|tazker|unique:employees',
'telphonenumber'=>'required',
'position'=>'required',
'supervisorname'=>'required',
'supervisornumber'=>'required',
'issuedate'=>'required',
'expiredate'=>'required',
'serialnumber'=>'required'
]);
答案 1 :(得分:0)
我按照Ohgodwhy在评论中所说的
解决了问题$this->validate($request,[
// 'BadgeCode'=>'required|string',
'BadgeCode'=>'required|unique:employees,BadgeCode',
'BadgeType'=>'required',
'company_id'=>'required',
'nationality_id'=>'required',
'lastname'=>'required',
'firstname'=>'required',
'tazker'=>'required|string|unique:employees,tazker',
'telphonenumber'=>'required',
'position'=>'required',
'supervisorname'=>'required',
'supervisornumber'=>'required',
'issuedate'=>'required',
'expiredate'=>'required',
'serialnumber'=>'required'
// $table->integer('nationality_id')->unsigned();
]);