我如何使用Laravel 5.5在PostgreSQL 9.6中使用完整的扩展ISO 8601日期时间格式

时间:2018-07-05 16:10:09

标签: php laravel datetime

我正在尝试使ISO 8601在Laravel 5.5中成为系统默认值。这是我的基本模型: app / Model.php

use Webpatser\Uuid\Uuid;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Model extends Eloquent {

    use SoftDeletes;
    protected $dateFormat = 'c';
    protected $primaryKey = "id";
    public $incrementing = false;
    protected $dates = ['deleted_at'];

    protected static function boot() {
        parent::boot();
        self::creating(function ($model) {
            $model->{$model->getKeyName()} = (string) Uuid::generate(4);
        });
    }
}

播种后,结果如下:

>>> App\Account::first();
=> App\Account {#2875
     id: "5b00bb95-9159-4fcf-93f1-2117bd450a99",
     name: "Ernesto Mayer Terry",
     type: "personal",
     email: "ernestomayerterry@hotmail.com",
     phone: "+9736734980597 ",
     status: "open  ",
     created_at: "2018-07-05 18:57:19+03",
     updated_at: "2018-07-05 18:57:19+03",
     deleted_at: null,
   }
>>> App\Account::first()->created_at;
InvalidArgumentException with message 'The format separator does not match
Trailing data'

2018-07-05T18:57:19 + 03:00-这是我期望保存在postgres中的格式

0 个答案:

没有答案