我正在尝试使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中的格式