dimanche 1 avril 2018

White spaces at end of timestamp while using Laravel format functions

I have a problem while using laravel functions for timestamp formatting, specifically while trying to get 'Month' of timestamps columns. For example:

this is the code of the migration:

Schema::create('posts', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id');
    $table->string('title');
    $table->text('body');
    $table->timestamp('created_at')->useCurrent();
    $table->timestamp('updated_at')->useCurrent();        
});

And this is an example of retrieving some of this data

    $first  =   factory(Post::class)->create();

    $second =   factory(Post::class)->create([

            'created_at' => \Carbon\Carbon::now()->subMonth()
        ]);

The result is something like this:

array:2 [
  0 => array:3 [
    "year" => "2018"
    "month" => "April    "
    "published" => 1
  ]
  1 => array:3 [
    "year" => "2018"
    "month" => "March    "
    "published" => 1
  ]
]

Note there the whitespace after the month. How should I deal with this?

I'm using postgres 10.3, Laravel 5.

I know I could trim my way up, but that could make the code insanely dirty. I would like to find a solution that makes this work 'as expected to'. Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2pVXpdq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire