I have ids in a string through ajax,
example:
"1,2"
and in my controller, I would like to update multiple rows of a product in one query using whereIn with id => [1,2].
ajax:
$('#add_product').click(function() {
var id = $('#get_value').val();
$.ajax({
type: 'POST',
url: "{{action('ProductController@updateProduct')}}",
data: {
id: id
},
success: function(data){
alert("success");
}
});
});
Controller :
public function updateProduct(Request $request){
$test_value = collect($request->id);
$updateProduct = Product::whereIn('id',$test_value)
->update(['title' => 'My title']);
}
But i have this error in the network :
SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: '1,2' (SQL: update "products" set "title" = "My title" where "id" in (1,2))