Changed the timezone but still getting UTC - laravel

I have changed the timezone for my laravel app to be Africa\Cairo, and i changed this in the app.php file
|--------------------------------------------------------------------------
| 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.
|
*/
'timezone' => 'Africa/Cairo',
but when i check in prodduction the time zone using Carbon::now(), i get the timezone is UTC
How can i set the timezone in Carbon

make sure you clear the cache, write this in your terminal (in the project directory):
php artisan config:cache
then start the project again to see the changes

Simply use Carbon::now('Africa/Cairo').
That should get you the correct time.
Hope this helps.

try this one
date_default_timezone_set('Africa/Cairo'); // set your default timezone
$date = Carbon::createFromFormat('F j, Y g:i:a', date('F j, Y g:i:a'));
dd($date->format('F j, Y g:i:a')); //November 27, 2020 7:00:pm

Carbon::now()->timezone('Australia/Sydney')->format('Y-m-d H:i:s');

Related

How does Laravel handle migrations that happen "out of order"?

So, let's say on the first of this month, I create branch A, with a migration file named 2020_04_01_113108_modify_request_logs_table.php
But let's say I don't merge this branch into my Master branch yet, and then I start working on branch B 2 days later, with a migration file named 2020_04_03_113108_create_label_logs_table.php
So on the 4th, I merge branch B into master and run php artisan migrate, and it runs the second migration.
And then on the 6th, I'm finally ready to merge branch A into master and run php artisan migrate. Is there anything that's going to go wrong with this migration? Does the migration system care that the dates of the files happened out of order? Will it ignore the A-branch file because it's already run a migration with a date later than that file?
Migration that haven't been executed yet, will be.
To check this before hand, you can run php artisan migrate:status to see which one are already executed ('Yes') and the ones that aren't ('No').
The output will look like this:
+------+-------------------------------------------------------------------+-------+
| Ran? | Migration | Batch |
+------+-------------------------------------------------------------------+-------+
| Yes | 2019_12_12_184629_create_users_table | 1 |
| Yes | 2020_03_27_153830_create_another_table | 1 |
| No | 2020_04_01_090622_modify_user_table | |
| Yes | 2020_04_11_102846_update_level | 1 |
| No | 2020_04_22_094132_dummy_migration | |
+------+-------------------------------------------------------------------+-------+
Acutally, Laravel will resolve this out of the box. All previously ran migrations are stored in your databse, in table migrations. Upon running new migrations, Laravel will compare them against the migrations that have already been run for this application, by looking in that migrations table.
I did some research, and actually found the methods in framework that do the described logic above. You can check them here.

Could not open /var/folders/n_/ laravel-excel.maatwebsite

i want to create download excel function using laravel-excel.maatwebsitelibrary. my code like below :
return Excel::download(new PembukuanExport, 'pembukuan.xlsx');
but when i ran it, it gave me error like this
Could not open /var/folders/n_/xh_10hm50dvbwg23cfq_kw3h0000gn/T/laravel-excel-DMBN3reNUrSiamYT for writing.
my laptop is macbook, been googling but cant find the right answer
It might be too late to answer this, but I guess you need to configure your excel.php config files.
Publish excel config files:
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"
Now in config/excel.php files you need to do configuration:
'temporary_files' => [
/*
|--------------------------------------------------------------------------
| Local Temporary Path
|--------------------------------------------------------------------------
|
| When exporting and importing files, we use a temporary file, before
| storing reading or downloading. Here you can customize that path.
|
*/
'local_path' => storage_path(),
/*
|--------------------------------------------------------------------------
| Remote Temporary Disk
|--------------------------------------------------------------------------
|
| When dealing with a multi server setup with queues in which you
| cannot rely on having a shared local temporary path, you might
| want to store the temporary file on a shared disk. During the
| queue executing, we'll retrieve the temporary file from that
| location instead. When left to null, it will always use
| the local path. This setting only has effect when using
| in conjunction with queued imports and exports.
|
*/
'remote_disk' => null,
],
This will set the temporary folder to your storage path which has permission to execute things. Hope this find helpful to others.
i solved this by changing User & Group in `httpd.conf.
Open httpd.config.
Search keyword "User or Group" and change it.
User your_mac_user and fill in Group staff

How setup current time zone on server in php and mysqli

I am trying this php funtion "date_default_timezone_set("Asia/Kolkata")" to set time zone, but inserting some other time in my database.
Try to check your setting first by: echo date_default_timezone_get();
try...
date_default_timezone_set('Asia/Kolkata');
echo date("y-m-d H:i:s");

code igniter's localhost mamp model works but view does not

I have a strange problem:
I am using MAMP and Codeigniter and I see that view is not showing anything on the browser. Model works and the DB is wired up.
Here is the code that does not work on the local host:
$this->load->view('test/db_tester_view',$data);
Sadly there is no error messages!!? but here is the config:
$config['base_url'] = 'http://localhost:8888';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
I spend 20 hours on this so your help is appreciated
Some tips:
Make sure error reporting is on, as usual (this should be in your bootstrap file, index.php):
error_reporting(E_ALL);
ini_set('display_errors', 1);
Make sure you did not disable these directives somewhere else in your script.
Windows and *NIX deal with uppercase/lowercase file names differently. Make sure your files are all normalized to lowercase to avoid problems with different operating systems.
The base url needs a trailing slash:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://localhost:8888/';
// OR...
$config['base_url'] = ''; // automagic
If you don't require the port to be set explicitly, you can remove it.

How to set date.timezone for CodeIgniter to work with php 5.3

When date.timezone in php.ini is commented out, it gives me:
A PHP Error was encountered
Severity: Warning
Message: main(): It is not safe to
rely on the system's timezone
settings. You are required to use
the date.timezone setting or the
date_default_timezone_set() function.
In case you used any of those methods
and you are still getting this
warning, you most likely misspelled
the timezone identifier. We selected
'America/Los_Angeles' for '-8.0/no
DST' instead
Filename: controllers/helloworld.php
Line Number: 2
When I have
date.timezone = "America/Los_Angeles"
It gives me this:
Server error The website encountered
an error while retrieving
http://localhost/ci/index.php/helloworld.
It may be down for maintenance or
configured incorrectly. Here are some
suggestions: Reload this web page
later. HTTP Error 500 (Internal Server
Error): An unexpected condition was
encountered while the server was
attempting to fulfill the request.
I am using php 5.3, CodeIgniter 2.0.0, and Apache 2.2.
Update 1:
I tried loading a test.php without CodeIgniter, where the first 3 lines of test.php is
date_default_timezone_set('America/Los_Angeles');
echo date("l j \of F Y h:i:s A");
And it works fine, different timezones also works fine too.
So I suspect the problem is from CodeIgniter.
If you Googled "CodeIgniter PHP 5.3" you would have found this article pretty quickly :)
http://philsturgeon.co.uk/blog/2009/12/CodeIgniter-on-PHP-5.3
To fix this, you only need to edit the main index.php for your CodeIgniter application:
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
This modification is something you will probably need to make for any CodeIgniter application running on PHP 5.3 and can easily be modified to your local timezone. There is a full list of supported timezones in the PHP manual here.
Yes, if you cannot directly edit the php.ini file, placing...
ini_set('date.timezone', 'America/New_York');
...as the first line in CI's index.php works fine.
Reference: PHP's Available Timezones
write in your index.php codeigniter...
/*
|---------------------------------------------------------------
| TimeZone
|---------------------------------------------------------------
|
| default Time Zone
|
*/
if ( function_exists( 'date_default_timezone_set' ) )
date_default_timezone_set('Asia/Jakarta');
Running well in my codeigniter
this is the simple way to do it
$timezone = "Asia/Calcutta";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
//echo date('d-m-Y H:i:s');
$localtime=date('H:i:s');
$sql="INSERT INTO hits (ip,edate,curtime,page_name) VALUES ('$ip', CURDATE(),'$localtime','$filename') ";
date.timezone is intended to go in your php.ini or .htaccess file.
you could do an ini_set('date.timezone', 'America/Los_Angeles'); in the first line of your script and get the desired results.
edit your config.php file
from
$config['time_reference'] = 'local';
to
$config['time_reference'] = 'UTC';

Resources