0
0
Laravelframework~5 mins

Timestamps management in Laravel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are timestamps in Laravel Eloquent models?
Timestamps are special columns named created_at and updated_at that Laravel automatically manages to record when a record is created and last updated.
Click to reveal answer
beginner
How do you disable automatic timestamps in a Laravel model?
Set the public property <code>public $timestamps = false;</code> inside the model class to stop Laravel from automatically updating <code>created_at</code> and <code>updated_at</code>.
Click to reveal answer
beginner
Which Laravel migration method adds created_at and updated_at columns?
The $table->timestamps(); method adds both created_at and updated_at columns as nullable timestamp fields.
Click to reveal answer
intermediate
How can you customize the names of timestamp columns in Laravel?
Override the <code>const CREATED_AT</code> and <code>const UPDATED_AT</code> constants in your model to use custom column names for timestamps.
Click to reveal answer
intermediate
What happens if you manually set updated_at to null in a Laravel model?
If you set updated_at to null, Laravel will treat it as no update time. But on saving, Laravel will overwrite it with the current timestamp unless timestamps are disabled.
Click to reveal answer
Which columns does Laravel automatically manage for timestamps?
Acreated_at and updated_at
Bcreated_on and updated_on
Ccreated and modified
Dstart_time and end_time
How do you add timestamp columns in a Laravel migration?
A$table->timestamps();
B$table->timestampColumns();
C$table->addTimestamps();
D$table->timeStamps();
To disable automatic timestamps in a Laravel model, you should:
ARemove timestamps columns from the database
BSet public $timestamps = false;
COverride save() method
DSet timestamps to null
Which constants do you override to rename timestamp columns in Laravel?
ASTART_TIME and END_TIME
BTIMESTAMP_CREATED and TIMESTAMP_UPDATED
CCREATED_AT and UPDATED_AT
DCREATED_ON and UPDATED_ON
If you want Laravel to stop updating timestamps but keep the columns, what do you do?
AOverride the save method
BDelete the timestamp columns
CSet timestamps to nullable
DSet public $timestamps = false;
Explain how Laravel manages timestamps in Eloquent models and how you can customize or disable this feature.
Think about the default columns and how Laravel updates them automatically.
You got /4 concepts.
    Describe the steps to add timestamps to a new Laravel database table and how to prevent Laravel from updating them automatically.
    Consider both migration and model changes.
    You got /2 concepts.