App with multiple models, timestamp issue

Published 4 months ago by nscherneck

I have an app with about 12 models, all of which save to my database (MySQL) at UTC, which is what I have my config set to...

config/app.php

'timezone' => 'UTC',

All but one are saving at UTC time, but I have one that saves at local time. It's a Photo model, which has a method that saves photos to AWS-S3. Here's the store method on the associated controller...

PhotosController.php

public function storeSystemPhoto(Request $request, System $system)
    {

      $this->validate($request, [
        'image' => 'required|mimes:jpg,jpeg,png,bmp'
      ]);

      // set the name of the file
      $this->setFileName($system);

      $photo = new Photo([
                  'path'            => $this->destinationFolder,
                  'file_name'       => $this->imageName,
                  'ext'             => $request->file('image')->getClientOriginalExtension(),
                  'caption'         => $request->caption,
                  'photoable_type'  => 'App\System',
                  'photoable_id'    => $system->id,
                  'added_by'        => Auth::id()
              ]);

      // save model
      $photo->save();

      // get instance of file
      $file = $this->getUploadedFile();

      // pass in the file and the model
      $this->saveImageFiles($file, $photo);

      flash('Success!', 'Photo added.');
      return redirect()->route('system_show', ['id' => $system->id]);
    }

I've verified all settings on my server (VPS on Digitalocean) are correct (UTC). I'm not sure where else I'd look to troubleshoot this. Any ideas?

Best Answer (As Selected By nscherneck)
vipin93

check your timezone echo Carbon::now()->tzName;

vipin93

if u want only in one model then use carbon

nscherneck

To clarify, I want them all to save at UTC time. Not sure why this one model is saving at local time (America/Los_Angeles).

vipin93

check your timezone echo Carbon::now()->tzName;

nscherneck

@vipin93 thanks for this. Though I haven't yet found where, looks like the Photo model is being set to local timezone somewhere.

balrajsahani8924

This beautiful 4th edition of Modern Combat 4 was well designed by the developers, they have changed a lot of options and they have made this game more interesting and special to gamers. http://appforfree.net/modern-combat-4-apk/

bhangad

It's time to relax and relieve your stress with this new version of King of Thieves Hack : https://swipefile.co/king-of-thieves-hack-cheats/ that has been released especially for casual players like

Monster Legends Hack https://swipefile.co/monster-legends-hack-cheats-free-gems-gold/ - Generate unlimited gems,golds and food using our Hack Tool for Monster Legends. 100 % efficiency, tested on all devices!

Sign In or create a forum account to participate in this discussion.