As we know, Laravel added two field "created_at" and "updated_at" with timestamps. So when new record will be add then created_at and updated_at columns update current timestamps updated and when update then update then updated_at column. This is a default by laravel.
But sometime, we dose not need to add created_at and updated_at column. So we have to stop add update those column, otherwise it returns error. So you can stop it using model $timestamps. Model contain timestamps variable with by default true value. So we have to simply false it. Like as bellow example:
LogActivity.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class LogActivity extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'subject', 'url', 'method', 'ip', 'agent', 'user_id'
];
protected $table = 'log_activities';
public $timestamps = false;
}
I hope you found your solution...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example