In this tutorial we’re going to share how to disable the automatic created_at
and updated_at
timestamps in Laravel’s Eloquent models, along with explanations of different scenarios:
1st step go to your model and put below code
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class AddurlCount extends Model
{
protected $connection = 'mysqlAddurl';
protected $table = 'links';
protected $fillable = ['project_name','url'];
public $timestamps = false;
}
2nd solutions
If you want to disable timestamps for all models in your application globally, you can do so by adding the following line to the boot
method of your AppServiceProvider
:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
Model::timestamps(false); // Disable timestamps for all models
}
Place this line within the boot
method of App\Providers\AppServiceProvider
. This will disable timestamps for all Eloquent models in your Laravel application.
Keep in mind that by disabling timestamps, you won’t have automatic updating of created_at
and updated_at
columns. You’ll need to manage these columns manually when creating or updating records in the database.
Now when you store the data update that value then timestamps Disable automatically.
Thanks for learning. šš