Laravelのタイムゾーンを使用して、デフォルトのデータベースDateFormatをISO 8601に設定します。

StackOverflow https://stackoverflow.com//questions/25023790

質問

タイトルはそれを言うと言っています。私はこの

を手に入れました
class mEloquent extends Eloquent {

   protected function getDateFormat()
   {
       return 'YYYY-MM-DDThh:mm:ss.sTZD';
   }

}
.

私のすべてのモデルはメロケントを拡張します。しかし、どのように私はテーブルを構築すべきですか?ただ

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateUsersTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('firstName');
        $table->string('lastName');
        $table->string('email')->unique();
        $table->string('password');
        $table->timestamps();
    });
} ......
.

通常どおり? このDateFormatを比較する方法またはShoud私はデフォルトのものを使い、タイムゾーンを別々に保存しますか?

他のヒント

ドキュメントに記載されているように、これを基本クラス 'Meloquent'

に追加します。
/**
 * The storage format of the model's date columns.
 *
 * @var string
 */
protected $dateFormat = 'c';
.

日付のシリアライズをチェックすることもできます。 https://laravel.com/docs/5.6/eLoquent-serialization#date-直列化

$date = Carbon::now();
echo $date->toW3cString();

$date = $this->repository->find($id);
echo $date->created_at->toW3cString();
.

出力

2018-04-14T18:35:58 + 00:00

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top