Domanda

Penso che il titolo lo dice: voglio usare ISO 8601 con Timezones come formato di dati predefinito in Laravels eloquente.Ho preso questo

class mEloquent extends Eloquent {

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

}
.

Tutti i miei modelli si estenderanno meloquente.Ma come dovrei costruire i tavoli?Solo

<?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();
    });
} ......
.

normale? Come posso confrontare questa data?O Shoud Uso solo quello predefinito e salva il fuso orario separatamente?

Altri suggerimenti

Come menzionato nei documenti, aggiungilo al tuo "Meloquentent" della tua classe base

/**
 * The storage format of the model's date columns.
 *
 * @var string
 */
protected $dateFormat = 'c';
.

È inoltre possibile controllare la data serializzations: https://laravel.com/docs/5.6/eloquent-serializzazione#Date-Serializzazione

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

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

output

.

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top