I had set timestamp in migrate laravel 5, like this:
$table->timestamp('verify_account')->nullable();
But, that is no set with timezone in postgresql. I want to set timestamp with timezone in postgresql, how to do it?
I had set timestamp in migrate laravel 5, like this:
$table->timestamp('verify_account')->nullable();
But, that is no set with timezone in postgresql. I want to set timestamp with timezone in postgresql, how to do it?
There is now a timestampsTz
function available when using Postgres. It should be available in Laravel 5.1 and above.
I had fix my problem.. I add a few code in laravel vendor directory
First step, open
vendor/laravel/framework/src/illuminate/Database/Schema/Blueprint.php
then, add this:
public function timestampz($column)
{
return $this->addColumn('timestamptz', $column);
}
After that, open
vendor/laravel/framework/src/illuminate/Database/Schema/Grammars/PostgresGrammar.php
then, add this:
protected function typeTimestamptz(Fluent $column)
{
return 'timestamp(0) with time zone';
}
How to use: In your migration file, that is like this:
$table->timestampz('yourcolumntimestampwithtimezone');
UPDATE
CustomBlueprint.php :
namespace App\Custom;
use Illuminate\Database\Schema\Blueprint;
class CustomBlueprint extends Blueprint {
public function timestampz($column)
{
return $this->addColumn('timestamptz', $column);
}
}
CustomPgsqlGrammar.php:
namespace App\Custom;
use Illuminate\Support\Fluent;
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
class CustomPgsqlGrammar extends PostgresGrammar {
protected function typeTimestamptz(Fluent $column)
{
return 'timestamp(0) with time zone';
}
}
Don't forgot for
use App\Custom\CustomBlueprint;
use App\Custom\CustomPgsqlGrammar;
use Illuminate\Database\Migrations\Migration;
And then add code below before
Schema::create
DB::connection()->setSchemaGrammar(new CustomPgsqlGrammar());
$schema = DB::connection()->getSchemaBuilder();
$schema->blueprintResolver(function($table, $callback) {
return new CustomBlueprint($table, $callback);
});
How to use:
$schema->create('users', function(CustomBlueprint $table) {
$table->timestampz('completing_registration');
}