Reputation: 1019
I Have my Laravel Lumen App on Ubuntu server and I changed the server time zone and my app saves the created_at, update_at successfully with the right time zone, Now when I fetch some tables data I noticed that the results time is not the same as in the Data base.
For example :
created_at in database = 2020-08-03 13:52:35
created_at in query result = 2020-08-03 10:52:35
Update as per requested, Below is my query
public function Outbox($id){
$orders = DB::table('order_details as o')
->join('user_profile as a','o.reciever_id','=','a.id')
->join('regions as r','a.province','=','r.province')
->where('o.sender_id' ,'=', $id)
->select('a.bid','r.ar_name as province','o.order_bar','o.price','o.delivery_cost','o.description','o.type','o.dropoff_time as time','o.status','o.visual_status','o.created_at')
->orderBy('o.created_at','desc')
->get();
if(count($orders) > 0){
return response()->json(['status_code'=>1000,'data'=>$orders , 'message'=>null],200);
}else{
return response()->json(['status_code'=>2000,'data'=>null , 'message'=>null],200);
}
}
What is the issue here ??
Any help will be much appreciated
Upvotes: 1
Views: 774
Reputation: 15
i've tried set the timezones in app.php and .env file. But nothing work. what works for me is, if you have the access to the database, you can change the timestamp datatype into datetime.
Upvotes: 0
Reputation: 380
It took me some time to find out, that in Lumen you have to add to your .env
file e.g.:
DB_TIMEZONE="Europe/Warsaw"
and this should solve the problem.
https://github.com/laravel/lumen-framework/blob/8.x/config/database.php
Upvotes: 1
Reputation: 2545
In your bootstrap/app.php
check your timezone in
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
and don't forget to add APP_TIMEZONE
in your .env
file
Updated
if you didn't find that line in bootstrap/app.php
add it after bootstraping environment variables like
<?php
require_once __DIR__.'/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
and in .env
add
APP_TIMEZONE=UTC
Upvotes: 1