Hello great people of SO
I hope you all have a great day!
I have an issue with my project timestamps
I have 2 Models, News
and Comments
During working on my project, I tried to replicate 'real world data'
So in my Seeder (NewsSeeder
),
use Faker\Generator as Faker;
use App\News;
...
public function run(Faker $faker) {
News::create([
'source' => $faker->url
'body' => $faker->paragraphs(random_int(1, 4), true)
]):
}
// Please note that, relationship between `News` and `Comments` is `hasMany`
// `News` hasMany `Comment`
// `Comment` belongs to a `User`
In my CommentSeeder
use Faker\Generator as Faker;
use App\News;
use App\Comment;
use App\User;
use Carbon\Carbon;
...
public function run() {
foreach (News::all() as $news) {
$i = 0;
for ($i; $i < random_int(1, 5); $i++) { // This will generate comments for each `News` with random amount
$news->comments()->create([
'user_id' => User::inRandomOrder()->first()->id,
'body' => $faker->paragraphs(random_int(1,3), true),
'created_at' => Carbon::parse($news->created_at)->addMinutes(random_int(1, 999)) // Comments created after the news is posted, make sense right?
]);
}
}
}
Everything works perfectly like I want it to be
The problem is: I see 2 timestamps format
Example:
"news": [
{
"source": ...
"body": ...
"created_at": "2021-02-10 15:19:09" // This
"comments": [
{
"user_id": ...
"body": ...
"created_at": "2021-02-10T16:22:33.000000Z" // and this
},
...
...
]
},
...
]
Q1:
Why they are different?
In model I'm using
$table->timestamps();
, which is Laravel's default timestamps format
Q2:
How to make all my models timestamps become like this: "2021-02-10T08:22:33.000000Z"
Thanks in advance
If there's any unclear explanation, I will edit a.s.a.p