From This answer I am trying to update department data. Code as below :
$id = Crypt::decrypt($id);
$rules = Department::$rules;
$rules['name'] = $rules['name'] . ',id,' . $id;
$rules['department_code'] = $rules['department_code'] . ',id,' . $id;
dump($rules);
$validator = Validator::make($data = $request->all(), $rules);
if ($validator->fails()) return Redirect::back()->withErrors($validator)->withInput();
$department = Department::findOrFail($id);
But the validator says :
The department code has already been taken.
The name has already been taken.
So whats wrong ?
My rules
array is:
public static $rules = [
'name' => 'required|unique:departments|max:255',
'department_code' => 'required|unique:departments|max:127',
];