Method one:
class User extends Model { public $timestamps = false; Public static function boot() {parent::boot(); Static ::creating(function ($model) {$model->created_at = $model->freshTimestamp(); //$model->updated_at = $model->freshTimeStamp(); }); {" date ":" 2020-09-27 13:47:12.000000 ", "timezone_type" : "created_at" : {" date ":" 2020-09-27 13:47:12.000000 ", "timezone_type" : Timezone: Asia/Shanghai}, created_at: 2020-09-27 13:49:39,Copy the code
Method 2:
class User extends Model { const UPDATED_AT = null; //const CREATED_AT = null; }Copy the code
Error: Using destroy to delete will cause an error
Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute() Delete does not affect and having does not affectCopy the code
Method 3:
Public function setUpdatedAt($value) {// Do nothing.} public function setUpdatedAt($value) {// Do nothing setCreatedAt($value) //{ // Do nothing. //} }Copy the code
Method 4:
Class User extends Model {public function setUpdatedAtAttribute($value) {// Do nothing function setCreatedAtAttribute($value) //{ // Do nothing. //} }Copy the code
It can also be set in Migration.
class CreatePostsTable extends Migration {
public function up() {
Schema::create('posts', function(Blueprint $table) {
$table->timestamp('created_at')
->default(DB::raw('CURRENT_TIMESTAMP'));
});
}
Copy the code