I have deleted created_at and updated_at from database but laravel tries to insert into these columns however I have deleted both from database and code in controller. I think something is cached. BTW I don't want to use public $timestamps = false
in model because it seems they are extra and unneeded.
Asked
Active
Viewed 1,607 times
3

Marcin Nabiałek
- 109,655
- 42
- 258
- 291

codepro
- 123
- 1
- 1
- 9
-
Did you remove them from the migrations? – Serge Nov 11 '17 at 17:25
-
yes! removed from db, migration, controller! – codepro Nov 11 '17 at 17:29
1 Answers
3
Well, in fact you need to set:
public $timestamps = false;
and it's not extra and unneeded because by default it's assumed models have timestamps (and in fact it's very reasonable to keep them almost in all tables).
Timestamps are used in process of saving record:
if ($this->usesTimestamps()) {
$this->updateTimestamps();
}
so there is no other shorter way when you are using Eloquent to set this property to false when you don't have those columns in table.

Marcin Nabiałek
- 109,655
- 42
- 258
- 291
-
so you mean each table needs those two columns and they are required?? i'm not sure! because i have several tables not having these two and are working properly! – codepro Nov 11 '17 at 18:24
-
If you use Eloquent for saving all tables should have timestamps by default except pivot tables. But if you are using for example query builder they are not needed. – Marcin Nabiałek Nov 11 '17 at 18:25
-
I don't know what pivot table is. What I know is I have used Eloquent and none of them need it! – codepro Nov 11 '17 at 18:32
-
So why you are asking on SO if you know that Eloquent doesn't need them? As I said by default Eloquent will always try to set created_at and updated_at columns if you don't set timestamps to false – Marcin Nabiałek Nov 11 '17 at 18:37