Timestamps #
When using Quick Models, Larawiz automatically adds timestamps, so there is no need to declare them inside the model definition.
models:
Post:
title: string
excerpt: string
body: longText
2
3
4
5
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('excerpt');
$table->longText('body');
$table->timestamps();
});
2
3
4
5
6
7
Timestamps with time zone #
You don't need time zones
Before going for timestamps with time zone, consider the following:
- PHP, like most languages, is aware of timezone shifts and DST in the future or past.
- Laravel always saves dates converted to UTC into the database.
In most scenarios, using time zone is not needed unless you expect to work on edge cases.
When using Quick Models, you can always use timestampsTz
in the columns definitions to swap the normal timestamps to ones with time zone data.
models:
Post:
title: string
body: string
Comment:
body: string
timestampsTz: ~
2
3
4
5
6
7
8
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('body');
$table->timestamps();
});
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('body');
$table->timestampsTz(); // Overridden from `timestamps`.
});
2
3
4
5
6
7
8
9
10
11
12
Disable Timestamps #
To disable timestamps, use a Custom Model. If the Custom Model doesn't include either timestamps
or timestampsTz
inside the columns declarations, timestamps will be disabled for the model.
models:
Post:
columns:
id: ~
title: string
excerpt: string
body: longText
2
3
4
5
6
7
class Podcast extends Model
{
public $timestamps = false;
}
2
3
4
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('excerpt');
$table->longText('body');
});
2
3
4
5
6
Custom Timestamps #
Only under a Custom Models you can change the default columns for timestamping using the timestamps
key.
For example, we can disable the default timestamps for updates by setting it as null
and point the column to use as creation date.
models:
Post:
columns:
id: ~
title: string
excerpt: string
body: longText
creation_date: timestamp nullable
timestamps:
created_at: creation_date
updated_at: ~
2
3
4
5
6
7
8
9
10
11
12
class Podcast extends Model
{
protected const CREATED_AT = 'creation_date';
protected const UPDATED_AT = null;
}
2
3
4
5
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('excerpt');
$table->longText('body');
$table->timestamp('creation_date')->nullable();
});
2
3
4
5
6
7