Created_at save with the wrong timezone - laravel

I have a laravel app and i'm trying to save the users checkins and checkouts to my database
i have a model Checkins and i record it like created_at and updated_at
on my localhost it save with the right time for my timezome ( Egypt ), i tried to changed app.php file to the following
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
| This is a bad thing really i think there is a problem within the server, the datetime
*/
'timezone' => 'EET',
it's working just fine on my localhost and save with the current right time, for the production it's save with UTC timezone
Also when i write in the production terminal the command date date, i get the following
Tue Mar 31 12:46:38 EET 2015
and i checked mysql for the timezone and i found it's getting the time from the system time
SELECT ##global.time_zone, ##session.time_zone;
SYSTEM
What's wrong here ?
UPDATE:
I created a php page with date('H:i:s'); and it's print the right time

To set the timezone for your Laravel app, change the 'timezone' in your config/app.php
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
| This is a bad thing really i think there is a problem within the server, the datetime
*/
'timezone' => 'America/Los_Angeles',
You can find the timezone you need here.

You have to change yout time zone in config/app.php
Also as is said here you must run following commands for your time zone changes to be saved:
php artisan cache:clear
php artisan view:clear
php artisan config:cache

Maybe you use insert or insertGetId to insert the data?
If you use Eloquent(like ->save()) to insert data, the time will be right.

As per php documentation It is strongly recommended that you use the correct time zone for your location, such as Asia/Shanghai or Australia/Perth Not use EET or CET.
Your can find timezone for your location here

Looks like you forgot to run php artisan config:cache.

Related

When and how do Laravel daily logging files get deleted?

I'm running Laravel 5.8 and using the built-in Laravel Log functionality. And I've created a few custom logs.
I set each of them to store the daily log files for 30 days, like so:
'reconciliation' => [
'driver' => 'daily',
'path' => storage_path('logs/reconciliation/reconciliation.log'),
'days' => 30
]
However, the logs don't stay for 30 days, like I've set them to. They stay for 7.
I've heard that there is another configuration called log_max_files, which might be what I'm looking for.
But all the references to log_max_files are from Laravel 5.4 and below. And I know that the logging functionality was revamped in 5.6. So I'm not sure if log_max_files even works anymore and I'd like to test it.
I've created a new log file with a date far outside the current 7-day range and I want to confirm that it gets deleted when the logs get cleared.
I'm just not sure when Laravel clears out the old logs. I couldn't find any in-depth information like that in the docs and my Google searching hasn't turned anything up.
I've tried restarting my server, running php artisan config:clear and php artisan cache:clear with no luck.
Does anyone actually know the process by which these log files get deleted and when that process runs?

Datetime is saving -5:30 in database

I'm passing datetime to api from my application, but is is saving 5:30 less in database. I'm using laravel for api & react in frontend application.
My date format is, Thu Oct 12 2017 11:00:00 GMT+0530 (IST).
When I checked in database, it saved as 2017-10-12 05:30:00.
How can I save exact datetime ?
Thank You
By default laravel set your application timezone to UTC, you have to configure the timezone in config/app.php as 'timezone' => 'Asia/Kolkata'
you can refer different timezones here

Unable to store session in Database in laravel 5.2

I recently upgraded my application from laravel 5.1 to 5.2 version. Also I am trying to store session in Database which is currently stored in file.
I have changed .env file to include SESSION_DRIVER=database. Also I have changed session.config file to include 'driver' => env('SESSION_DRIVER', 'database') and generated required session table.
But when I tried to login to the application I am getting TokenMismatchException in VerifyCsrfToken.php line 67: If I change SESSION_DRIVER=file then application is working as expected.
But this was not the case in Laravel 5.1 version.
What is changed in Laravel 5.2 version and what steps are required to store user session in database?
I had to deal with this issue myself as well. So the initial steps are as you had already mentioned in your question.
On fresh install of laravel and verify that everything works, change the SESSION_DRIVER=file to SESSION_DRIVER=database
Run the following commands IN ORDER in your console within the directory of your app:
php artisan session:table
composer dump-autoload
php artisan migrate
(This step might be different from what you did) In your config\session.php file search for:
'driver' => env('SESSION_DRIVER', 'file'),
and change it to the following
'driver' => env('SESSION_DRIVER', 'app.database'),
Within the same config\session.php file change the encrypt configuration to true
Set your connection and table name settings appropriately
'connection' => 'database_name_here',
'table' => 'sessions', //here you can change but sessions is recommended until you get more comfortable with how it all works
Attempt to login to your application and check your database to see if it all works.
If more help is needed you can also check a few resources that have helped me solve the issue. Keep in mind these resources are of people having similar issues but maybe your problem is similar to theirs. Only way to find out is to investigate. Hope this helps! =) :
https://laracasts.com/discuss/channels/laravel/how-to-store-users-id-in-session-table-laravel-5
https://laravel.com/docs/5.2/session
(Video tutorial on Laravel Sessions, VERY good place to help you get to where you need to be!)
https://www.youtube.com/watch?v=-FMecyZs5Cg
look it's ok to go with it manual but why don't u use the php artisan make:auth
it creates every thing u need for authentication and also helps u keeping the session instead of doing it manual ?

Laravel Timezone UTC but got a London

I have a question
In Laravel config/app timezone = UTC
But my localhost is in Japan, `created_at time is London
I not sure that I have understood your question but... you are saying your locale config is UTC therefore you application runs with the correct configured timezone.
If you want to set a different timezone you should change it in config/app.php.
Check all available timezones in php: http://php.net/manual/es/timezones.php
Kind regards
You can set your timezone in laravel config/app like this
'timezone' => 'Asia/Tokyo'
This should solve your problem. With reference to http://php.net/manual/en/timezones.php
Regards.

Time zone problem in Codeigniter

I have set the default time zone like date_default_timezone_set('America/New_York');
But the time is exactly 4 hrs advance.
(ie) if Current time is 6:00:00 then its saving as 10:00:00
Don't know whats wrong. Its working perfectly in localhost but not in godaddy server.
Have you tried asking godaddy? I'm fairly sure date_default_timezone_set is a native PHP function and not related explicitly to CodeIgniter:
http://php.net/manual/en/function.date-default-timezone-set.php

Resources