Utilizing x-editable to generate an editable form that makes ajax requests. The form is structured as follows:
<a href="#" class="editable editable-click" id="mileage"
data-name="mileage"
data-type="number"
data-pk="{{ $car->id }}"
data-original-title="Enter mileage">
{{ $car->mileage }}
</a>
Next, we have the JavaScript code:
$('#mileage').editable({
url: '{{ route('changeMileage', $car->id) }}',
type: 'number',
pk: {{ $car->id }},
name: 'mileage',
title: 'Enter mileage in km',
validate:function(value){
if ($.trim(value) === '') {
return "Field is required";
}
}
})
Within my controller:
$car = Car::where('id', $id)->first();
$this->validate($request, [
'value' => 'number|min:' . $car->mileage . '|max:999999',
]);
$car->update([$car->mileage => $request->value]);
The controller logic may seem disorganized due to exploration of different versions. Validation is required (ensure entered mileage is not less than existing value).
However, upon sending the request, I encounter an
Integrity constraint violation: 1048
error related to an empty mileage
field. Despite monitoring the intended request from the browser as name=mileage&value=325000&pk=1
, dd($request->value)
returns null
.
The controller appears to be missing the value
. Any suggestions for a solution?
P.S. Omission of checking for pk
value, as the current page has only one editable field with necessary id
information.
P.P.S. Attempted various methods, but even dd($request->all())
yields an empty array - [].