Set the default DateFormat database to ISO 8601 with time zones in Laravel

I think the name says it: I want to use ISO 8601 with time zones as the default DateTime-Format in Laravels Eloquent. I got it

class mEloquent extends Eloquent {

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

}

All my models will expand. But how do I build tables? Simply

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

normally? How can I compare this date format? Or shoud I just use the default and keep the timezone separate?

+4
source share
2 answers

Its very easy if you follow the docs.

PHP date ISO 8601 PHP5, , 'c'.

http://php.net/manual/en/function.date.php

Laravel Carbon. Carbon DateTime, format, date.

( ), . Carbon format, ISO 8601.

, laravel - :

public function getPublishedAt8601Attribute()
{
    return $this->published_at->format('c');
}

:

// Prints something like: 2016-10-13T21:48:00+03:00
echo $post->published_at_8601;
+3
$date = Carbon::now();
echo $date->toW3cString();

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

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

0

All Articles