I have an entity activities with the following Form Request as indicated in the documentation
public function rules()
{
return [
'name' => "required|max:200|unique:activities,name,". $this->activity_id
];
}
When editing, send the data by axios:
$("#frmEditActivity").submit(function (e) {
e.preventDefault();
axios.patch("/admin/actividades/" + $("#frmEditActivity #activity_id").val(), $(this).serialize())
.then(function (response) {
self.loadTable();
toastr.success(response.data);
$("#mdlEdit").modal('hide');
})
.catch(function (error) {
error.response.status == 422 ? toastr.error(error.response.data.errors.name) : "Ocurrió un error. Intentelo de nuevo!";
});
});
and when sending the data I receive the following error:
SQLSTATE [23000]: Integrity constraint violation: 1062 Duplicate entry 'xxx' for key 'activities_name_unique
The route is:
Route::resource('actividades', 'ActivityController', [
'except' => 'create', 'edit', 'show',
'names' => 'activities'
]);
The driver is:
public function update(ActivityRequest $request, ActivityModel $activity)
{
if ($request->ajax()) {
if ($this->activityRepo->edit($request->all(), $activity)) {
return response()->json('Actividad editada correctamente.');
}
return response()->json('Ocurrió un error. Por favor inténtelo nuevamente!');
}
return redirect(route('admin.activities.index'));
}