TL;DR:没有2020-08-09
在 json 响应中。
我刚刚发现我的行为很奇怪Laravel 7.x
今天的项目。正如上面标题所提到的,created_at
and updated_at
json 响应与 artisan 命令生成的响应不同。
当我更改默认时区时出现问题app/config.php
from UTC
to Asia/Jakarta
。为了清楚起见,这是我的查询的一些结果:
mysql> select * from field_reports
+----+------------+-----------+---------+-------------+------------------------+--------------------------------------------+---------------------+---------------------+
| id | company_id | branch_id | user_id | title | chronology | images | created_at | updated_at |
+----+------------+-----------+---------+-------------+------------------------+--------------------------------------------+---------------------+---------------------+
| 1 | 1 | 1 | 1 | example | example chronology | [{"url": "some_url", "path": "some_path"}] | 2020-08-08 16:02:53 | 2020-08-08 16:29:46 |
| 2 | 1 | 1 | 1 | new fr | new chronology | [{"url": "some_url", "path": "some_path"}] | 2020-08-08 18:31:32 | 2020-08-08 18:31:32 |
| 3 | 1 | 1 | 1 | new fr | new chronology | [{"url": "some_url", "path": "some_path"}] | 2020-08-08 18:32:48 | 2020-08-08 18:32:48 |
| 4 | 1 | 1 | 1 | example | example chronology | [{"url": "some_url", "path": "some_path"}] | 2020-08-09 01:33:31 | 2020-08-09 01:33:31 |
| 5 | 1 | 1 | 1 | NEW | NEW CHRONOLOGY | [{"url": "some_url", "path": "some_path"}] | 2020-08-09 01:44:41 | 2020-08-09 01:44:41 |
+----+------------+-----------+---------+-------------+------------------------+--------------------------------------------+---------------------+---------------------+
5 rows in set (0.02 sec)
php artisan tinker
>>> App\User::first()->fieldReports;
=> Illuminate\Database\Eloquent\Collection {#4033
all: [
App\FieldReport {#4035
id: 2,
company_id: 1,
branch_id: 1,
user_id: 1,
title: "new fr",
chronology: "new chronology",
images: "[{"url": "some_url", "path": "some_path"}]",
created_at: "2020-08-08 18:31:32",
updated_at: "2020-08-08 18:31:32",
},
App\FieldReport {#4038
id: 3,
company_id: 1,
branch_id: 1,
user_id: 1,
title: "new fr",
chronology: "new chronology",
images: "[{"url": "some_url", "path": "some_path"}]",
created_at: "2020-08-08 18:32:48",
updated_at: "2020-08-08 18:32:48",
},
App\FieldReport {#4039
id: 4,
company_id: 1,
branch_id: 1,
user_id: 1,
title: "example",
chronology: "example chronology",
images: "[{"url": "some_url", "path": "some_path"}]",
created_at: "2020-08-09 01:33:31",
updated_at: "2020-08-09 01:33:31",
},
App\FieldReport {#4040
id: 5,
company_id: 1,
branch_id: 1,
user_id: 1,
title: "NEW",
chronology: "NEW CHRONOLOGY",
images: "[{"url": "some_url", "path": "some_path"}]",
created_at: "2020-08-09 01:44:41",
updated_at: "2020-08-09 01:44:41",
},
],
}
>>>
这是来自POSTMAN中的get请求,这是问题所在,请看一下时间戳:
{
"success": true,
"data": [
{
"id": 2,
"company_id": 1,
"branch_id": 1,
"user_id": 1,
"title": "new fr",
"chronology": "new chronology",
"images": "[{\"url\": \"some_url\", \"path\": \"some_path\"}]",
"created_at": "2020-08-08T11:31:32.000000Z",
"updated_at": "2020-08-08T11:31:32.000000Z"
},
{
"id": 3,
"company_id": 1,
"branch_id": 1,
"user_id": 1,
"title": "new fr",
"chronology": "new chronology",
"images": "[{\"url\": \"some_url\", \"path\": \"some_path\"}]",
"created_at": "2020-08-08T11:32:48.000000Z",
"updated_at": "2020-08-08T11:32:48.000000Z"
},
{
"id": 4,
"company_id": 1,
"branch_id": 1,
"user_id": 1,
"title": "example",
"chronology": "example chronology",
"images": "[{\"url\": \"some_url\", \"path\": \"some_path\"}]",
"created_at": "2020-08-08T18:33:31.000000Z",
"updated_at": "2020-08-08T18:33:31.000000Z"
},
{
"id": 5,
"company_id": 1,
"branch_id": 1,
"user_id": 1,
"title": "NEW",
"chronology": "NEW CHRONOLOGY",
"images": "[{\"url\": \"some_url\", \"path\": \"some_path\"}]",
"created_at": "2020-08-08T18:44:41.000000Z",
"updated_at": "2020-08-08T18:44:41.000000Z"
}
]
}
最后,这是控制器中的脚本:FieldReportController.php
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$fieldReports = $request->user()->fieldReports;
return response()->json([
'success' => true,
'data' => $fieldReports,
]);
}
我尝试过以下几种方法:
- Run
php artisan config:clear
- Run
php artisan cache:clear
- Run
php artisan route:clear
- Run
valet restart
但问题仍然存在。有什么线索吗?