ven*_*999 1 php laravel eloquent
我尝试从数据库中选择create_data,数据库中的日期格式类似于“2021-05-18 11:06:01”,但是当我检索并显示它时,它将显示类似于“2021-05”的格式-18T03:06:01.000000Z”。有谁知道为什么会变成这样吗?我想要的日期实际上就像数据库存储“2021-05-18 11:06:01”。然而,DB内的create_date格式是UTC +8,但接收时会显示UTC格式。
数据返回
[0] => Array (
[id] => 1
[log_name] => login
[description] => login
[subject_type] => App\Models\Users
[subject_id] => 0
[causer_type] => App\Models\User
[causer_id] => 2
[properties] => ""
[created_at] => 2021-05-18T03:06:01.000000Z
);
Run Code Online (Sandbox Code Playgroud)
代码
$lastLoggedActivity = ActivityLog::where('causer_id', $userid)
->orWhereIn('subject_id', $selectparentid)
->with('getLogType')
->with('getCauserDetails')
->orderBy('created_at', 'desc')
->get()
->toArray();
Run Code Online (Sandbox Code Playgroud)
在 ActivityLog 模型中添加这个,
use Carbon\Carbon;
public function getCreatedAtAttribute($value)
{
return Carbon::parse($value)->format('Y-m-d H:i:s');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12032 次 |
| 最近记录: |