SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel laravel laravel

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel


null is different than not existend. If you want to set null as a value you have to write it in your query:

 ... ('2016-12-06 06:56:01',27, null, '2016-12-06 06:56:01'))

Also the datetime format is wrong. You have to enter it as a string.


Set 0 for unit_id before query, if it null/empty. See example:

if(!isset($unit_id) || empty($unit_id)) $unit_id = 0;..//insert query rest code


Just had the same issue and in my case it was a silly mistake in my controller.

What I did was I returned the whole object instead of just the id, like so:

  public function store($id, Request $request) {    $post = Post::find($id);    $comment = new Comment;    $comment->text = $request->comment;    $comment->post_id = $post; <--- HERE IS THE MISTAKE     $comment->post_id = $post->id; <--- HERE IS THE FIX    $comment->user_id = Auth::id();    $comment->save();    return back();  }