I'm using
Laravel Framework 9.37.0
PHP 8.1.10
Using postman for get and add data
I try to get data from MySQL database using eloquent
$investment = Investment::where('user_id', $user_id)->orderBy('created_at', 'DESC')->get();
return $investment;
That code return different timestamp from my database
This is timestamp from my database
created_at = 2022-11-01 11:26:55
updated_at = 2022-11-01 11:26:55
But this is timestamp from my postman
created_at = 2022-11-01 04:26:55
updated_at = 2022-11-01 04:26:55
Result is different 7 Hours. I Already set my config/app.php "timezone" to "Asia/Jakarta". I try to set in UTC and return different timestamp too
This is my model
class Investment extends Model
{
use HasFactory;
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i:s',
'updated_at' => 'datetime:Y-m-d H:i:s',
];
public function user()
{
return $this->belongsTo(User::class,'user_id');
}
public function plan()
{
return $this->belongsTo(PlanList::class, 'plan_id');
}
}
Timestamp is correct when I add data, it is only wrong when I GET data. But if using DB::table()... timestamp is correct.
Can someone explain why this returns a different timestamp when using eloquent?
I try to change timezone to UTC but still return different timestamp.