2

I am trying to insert data into one table, my table have three columns, id-auto increment, phoneno, login_date. i am trying the below code.

$input = Request::has('phoneno');
$login_history = new LoginHistory;
$login_history->phoneno=$input;
$login_history->login_date=date('Y-m-d H:i:s');
$login_history->save();

but i am getting the below error.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into login_history (phoneno, login_date, updated_at, created_at) values (1, 2015-12-14 08:55:25, 2015-12-14 08:55:25, 2015-12-14 08:55:25))

3 Answers 3

2

You don't have created_at and updated_at columns in your table that Eloquent expects all models have by default. Either create those columns or simply disable timestamps for that model by setting $timestamps property accordingly:

class LoginHistory {
  protected $timestamps = false;
}
Sign up to request clarification or add additional context in comments.

Comments

2

This is because you do not have the field updated_at in your database table.
Make sure to add:

$table->timestamps()

to your migration and re-migrate the database ( or update the table ).

This will add the fields created_at and updated_at.

Comments

2

The reason for this error is simple. Laravel by default assumes that your table has created_at and updated_at fields. hence, ->save() method tries to store the timestamps as you can see in the query.

If you do not want these to be included, add public $timestamps = false; in your Model.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.