Top Menu

By default, Laravel Eloquent models assume your table has timestamp fields – created_at and updated_at. But there’s plenty of things you can do to customize them or perform some interesting operations.

Deepcool Fan Hub Control 4PWM Fan Speed Supports Fan with 3Pin/4Pin Cooling FH-04
If your database table doesn’t have those fields, and you will try to do something like Model::create($arrayOfValues); – you will get SQL error. Laravel would try to automatically fill in created_at/updated_at and wouldn’t find them.
To disable that automatic timestamps, in your Eloquent Model you need to add one property:
app/ModelName.php
class ModelName extends Model{
public $timestamps = FALSE;
//add given above line in model
}

Change Timestamp Column Names

What if you’re working with a non-Laravel DB and your timestamp columns are named differently? Maybe, you have create_time and update_time. Luckily, you can specify them in the model, too:
Best Sellers in Software
class ModelName extends Model
{
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Close