mihiran
mihiran

Reputation: 1

php laravel error with database data insertion

i am new to PHP Laravel. I create a table using PHP artisan migrate.Using PHP artisan tinker command i try to insert the data to database .but it gives the following error.what is the reason for this.

DB::table('users')
->insert(['id'=>'1','name'=>'admin','email'=>'[email protected]','remember_token'=>'1','created_at'=>' ','updated_at' => ' ']);

error message:

Illuminate/Database/QueryException with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: ' ' for column 'created_at' at row 1 (SQL: insert into `users` (`id`, `name`, `email`, `remember_token`, `created_at`, `updated_at`) values (1, admin, [email protected], 1,  ,  ))'

Upvotes: 0

Views: 163

Answers (1)

Farkie
Farkie

Reputation: 3337

You're trying to insert 'created_at'=>' ', try using

'created_at'=> (new DateTime())->format('Y-m-d H:i:s')

and it should insert for you.

Upvotes: 0

Related Questions