I\'m in the process of converting one of our web applications from CodeIgniter to Laravel. However at this moment we don\'t want to add the updated_at
/ c
In case you want to remove timestamps from existing model, as mentioned before, place this in your Model:
public $timestamps = false;
Also create a migration with following code in the up()
method and run it:
Schema::table('your_model_table', function (Blueprint $table) {
$table->dropTimestamps();
});
You can use $table->timestamps()
in your down()
method to allow rolling back.
Eloquent Model:
class User extends Model
{
protected $table = 'users';
public $timestamps = false;
}
Or Simply try this
$users = new Users();
$users->timestamps = false;
$users->name = 'John Doe';
$users->email = 'johndoe@example.com';
$users->save();
Override the functions setUpdatedAt()
and getUpdatedAtColumn()
in your model
public function setUpdatedAt($value)
{
//Do-nothing
}
public function getUpdatedAtColumn()
{
//Do-nothing
}
If you only need to only to disable updating updated_at just add this method to your model.
public function setUpdatedAtAttribute($value)
{
// to Disable updated_at
}
This will override the parent setUpdatedAtAttribute() method. created_at will work as usual. Same way you can write a method to disable updating created_at only.