I have a model with a number of fillable fields
class Customer extends Model
{
protected $fillable = [...,'my_field'...]
}
I also have a controller to update this table with the following method:
public function update(Request $request, Customer $customer)
{
error_log($request->all());
$customer->update($request->all());
return response()->json($customer, 200);
}
If I send a request with a body containing an empty string:
{
...
"my_field": "",
...
}
this field will be stripped out by the $request->all() method resulting in an array like this:
Array
(
...
[my_field] =>
...
)
which then creates this error:
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'my_field' cannot be null
But it should not be null, I want it to be an empty string. What is the standart way to deal with this?