In Laravel I have a model that is created only but not updated. So, I want to remove only the updated_at
field. But the created_at
field is required.
So how can I remove only the updated_at
field while keeping the created_at
field?
In your model add these two lines:
public $timestamps = ["created_at"]; //only want to used created_at column
const UPDATED_AT = null; //and updated by default null set
second way:
public $timestamps = false; //by default timestamp true
add function like this:
public function setCreatedAtAttribute($value) {
$this->attributes['created_at'] = \Carbon\Carbon::now();
}
for more info about laravel timestamp see
The answer you checked as the solution is not what the question asked for.
you can drop the updated_at
column just in the table creation migration:
Schema::create('sample', function (Blueprint $table)
$table->id();
$table->timestamps();
$table->dropColumn('updated_at');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With