@matheenulla you're passing an empty value for lead_id field. If the field is nullable change $leadid = ''; to $leadid = null;.
Mar 4, 2020
6
Level 51
Invalid date time format: 1366 Incorrect integer value
Hi
while inserting a record I am getting an error.
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column `usermanagement`.`estimate_lists`.`lead_id` at row 1 (SQL: insert into `estimate_lists` (`estimate_date`, `valiuntill_date`, `client_id`, `lead_id`, `tax`, `second_tax`, `notes`, `updated_at`, `created_at`) values (2020-03-04, 2020-03-11, 2, , 10%, 10%, testing, 2020-03-04 09:38:45, 2020-03-04 09:38:45))
I used mutators but getting the same error when I tried to validate in the controller I am getting the same error. I am inserting a record using ajax.
model
// this is not working
public function setAttribute($key, $value)
{
if(in_array($key, ['estimate_date', 'valiuntill_date'])){
$this->attributes[$key] = Carbon::createFromFormat('d-m-Y', $value)->format('Y-m-d');
return $this;
}
return parent::setAttribute($key, $value);
}
controller
public function store(Request $request)
{
if(preg_match("/[a-z]/i",$request->client))
{
$leadid = ltrim($request->client,"le");
$clientid ='';
}
else
{
$leadid = '';
$clientid = $request->client;
}
$estimatedate = Carbon::parse($request->estimatedate)->format('Y-m-d');
$validate = Carbon::parse($request->validuntill)->format('Y-m-d');
EstimateList::create([
'estimate_date' => $estimatedate,
'valiuntill_date' => $validate,
'client_id' => $clientid,
'lead_id' => $leadid,
'tax' => $request->tax,
'second_tax' => $request->secondtax,
'notes' => $request->notes,
]);
return response()->json('Estimate List Added Successfully');
}
thank you
Please or to participate in this conversation.