Adding seconds with Carbon











up vote
0
down vote

favorite












The idea is that I need to get end_date from the Auction via this model, which is inside a database, in MySQL timestamp format (I use phpmyadmin, if it matters, ex. 2018-11-14 04:58:07). So when I get the end_date, the idea is to increment it by few seconds (ex. 10 seconds) via Carbon addSeconds() function and then write it again into the DB. Here is the controller where it's done and my Auction model.
What happens is that i get the FatalThrowableError 'Call to a member function addSeconds() on integer'. I played around quite a lot and can't seem to find right format for the secs2 variable.



Auction.php



public $id;
public $name;
public $descript;
public $price;
public $pic;
public $end_date;
public $offers;
public $offered_by;

public function get(){
$result =
DB::table('auctions')
->select('*')
->where('id', '=', $this->id)
->first();
return $result;
}

public function increment($id){
$result =
DB::table('auctions')
->where('id', $id)
->update([
'offers' => DB::raw('offers + 1'),
'end_date' => $this->end_date
]);
return $result;
}


AuctionController.php



    public function offer($id, Request $request){
$auction = new Auction();
$auction->id = $id;

$secs = $auction->get()->end_date;
$secs2 = strtotime($secs);
$secs2->addSeconds(120);

$auction->end_date = $secs2;
//dd($secs2);

$auction->increment($id);
}









share|improve this question


























    up vote
    0
    down vote

    favorite












    The idea is that I need to get end_date from the Auction via this model, which is inside a database, in MySQL timestamp format (I use phpmyadmin, if it matters, ex. 2018-11-14 04:58:07). So when I get the end_date, the idea is to increment it by few seconds (ex. 10 seconds) via Carbon addSeconds() function and then write it again into the DB. Here is the controller where it's done and my Auction model.
    What happens is that i get the FatalThrowableError 'Call to a member function addSeconds() on integer'. I played around quite a lot and can't seem to find right format for the secs2 variable.



    Auction.php



    public $id;
    public $name;
    public $descript;
    public $price;
    public $pic;
    public $end_date;
    public $offers;
    public $offered_by;

    public function get(){
    $result =
    DB::table('auctions')
    ->select('*')
    ->where('id', '=', $this->id)
    ->first();
    return $result;
    }

    public function increment($id){
    $result =
    DB::table('auctions')
    ->where('id', $id)
    ->update([
    'offers' => DB::raw('offers + 1'),
    'end_date' => $this->end_date
    ]);
    return $result;
    }


    AuctionController.php



        public function offer($id, Request $request){
    $auction = new Auction();
    $auction->id = $id;

    $secs = $auction->get()->end_date;
    $secs2 = strtotime($secs);
    $secs2->addSeconds(120);

    $auction->end_date = $secs2;
    //dd($secs2);

    $auction->increment($id);
    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      The idea is that I need to get end_date from the Auction via this model, which is inside a database, in MySQL timestamp format (I use phpmyadmin, if it matters, ex. 2018-11-14 04:58:07). So when I get the end_date, the idea is to increment it by few seconds (ex. 10 seconds) via Carbon addSeconds() function and then write it again into the DB. Here is the controller where it's done and my Auction model.
      What happens is that i get the FatalThrowableError 'Call to a member function addSeconds() on integer'. I played around quite a lot and can't seem to find right format for the secs2 variable.



      Auction.php



      public $id;
      public $name;
      public $descript;
      public $price;
      public $pic;
      public $end_date;
      public $offers;
      public $offered_by;

      public function get(){
      $result =
      DB::table('auctions')
      ->select('*')
      ->where('id', '=', $this->id)
      ->first();
      return $result;
      }

      public function increment($id){
      $result =
      DB::table('auctions')
      ->where('id', $id)
      ->update([
      'offers' => DB::raw('offers + 1'),
      'end_date' => $this->end_date
      ]);
      return $result;
      }


      AuctionController.php



          public function offer($id, Request $request){
      $auction = new Auction();
      $auction->id = $id;

      $secs = $auction->get()->end_date;
      $secs2 = strtotime($secs);
      $secs2->addSeconds(120);

      $auction->end_date = $secs2;
      //dd($secs2);

      $auction->increment($id);
      }









      share|improve this question













      The idea is that I need to get end_date from the Auction via this model, which is inside a database, in MySQL timestamp format (I use phpmyadmin, if it matters, ex. 2018-11-14 04:58:07). So when I get the end_date, the idea is to increment it by few seconds (ex. 10 seconds) via Carbon addSeconds() function and then write it again into the DB. Here is the controller where it's done and my Auction model.
      What happens is that i get the FatalThrowableError 'Call to a member function addSeconds() on integer'. I played around quite a lot and can't seem to find right format for the secs2 variable.



      Auction.php



      public $id;
      public $name;
      public $descript;
      public $price;
      public $pic;
      public $end_date;
      public $offers;
      public $offered_by;

      public function get(){
      $result =
      DB::table('auctions')
      ->select('*')
      ->where('id', '=', $this->id)
      ->first();
      return $result;
      }

      public function increment($id){
      $result =
      DB::table('auctions')
      ->where('id', $id)
      ->update([
      'offers' => DB::raw('offers + 1'),
      'end_date' => $this->end_date
      ]);
      return $result;
      }


      AuctionController.php



          public function offer($id, Request $request){
      $auction = new Auction();
      $auction->id = $id;

      $secs = $auction->get()->end_date;
      $secs2 = strtotime($secs);
      $secs2->addSeconds(120);

      $auction->end_date = $secs2;
      //dd($secs2);

      $auction->increment($id);
      }






      php laravel date timestamp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 3:42









      Младен Карић

      137




      137
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          If you want to use addSeconds method, you can't convert your time into number first..
          ex:



          Carbon::parse($auction->get()->end_date)->addSeconds(120)->format('H:i:s');





          share|improve this answer























          • Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
            – Младен Карић
            Nov 12 at 4:02










          • can you print out the result of Carbon::parse($auction->get()->end_date) ?
            – James Riady
            Nov 12 at 4:05










          • this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
            – Младен Карић
            Nov 12 at 4:11










          • So apparently that made it add seconds the right way.
            – Младен Карић
            Nov 12 at 4:13










          • I have updated my answer,, Please try it again
            – James Riady
            Nov 12 at 4:13













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255684%2fadding-seconds-with-carbon%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          If you want to use addSeconds method, you can't convert your time into number first..
          ex:



          Carbon::parse($auction->get()->end_date)->addSeconds(120)->format('H:i:s');





          share|improve this answer























          • Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
            – Младен Карић
            Nov 12 at 4:02










          • can you print out the result of Carbon::parse($auction->get()->end_date) ?
            – James Riady
            Nov 12 at 4:05










          • this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
            – Младен Карић
            Nov 12 at 4:11










          • So apparently that made it add seconds the right way.
            – Младен Карић
            Nov 12 at 4:13










          • I have updated my answer,, Please try it again
            – James Riady
            Nov 12 at 4:13

















          up vote
          1
          down vote













          If you want to use addSeconds method, you can't convert your time into number first..
          ex:



          Carbon::parse($auction->get()->end_date)->addSeconds(120)->format('H:i:s');





          share|improve this answer























          • Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
            – Младен Карић
            Nov 12 at 4:02










          • can you print out the result of Carbon::parse($auction->get()->end_date) ?
            – James Riady
            Nov 12 at 4:05










          • this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
            – Младен Карић
            Nov 12 at 4:11










          • So apparently that made it add seconds the right way.
            – Младен Карић
            Nov 12 at 4:13










          • I have updated my answer,, Please try it again
            – James Riady
            Nov 12 at 4:13















          up vote
          1
          down vote










          up vote
          1
          down vote









          If you want to use addSeconds method, you can't convert your time into number first..
          ex:



          Carbon::parse($auction->get()->end_date)->addSeconds(120)->format('H:i:s');





          share|improve this answer














          If you want to use addSeconds method, you can't convert your time into number first..
          ex:



          Carbon::parse($auction->get()->end_date)->addSeconds(120)->format('H:i:s');






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 4:16

























          answered Nov 12 at 3:52









          James Riady

          691422




          691422












          • Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
            – Младен Карић
            Nov 12 at 4:02










          • can you print out the result of Carbon::parse($auction->get()->end_date) ?
            – James Riady
            Nov 12 at 4:05










          • this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
            – Младен Карић
            Nov 12 at 4:11










          • So apparently that made it add seconds the right way.
            – Младен Карић
            Nov 12 at 4:13










          • I have updated my answer,, Please try it again
            – James Riady
            Nov 12 at 4:13




















          • Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
            – Младен Карић
            Nov 12 at 4:02










          • can you print out the result of Carbon::parse($auction->get()->end_date) ?
            – James Riady
            Nov 12 at 4:05










          • this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
            – Младен Карић
            Nov 12 at 4:11










          • So apparently that made it add seconds the right way.
            – Младен Карић
            Nov 12 at 4:13










          • I have updated my answer,, Please try it again
            – James Riady
            Nov 12 at 4:13


















          Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
          – Младен Карић
          Nov 12 at 4:02




          Was that a proposed solution? When I try your version i get 'Call to a member function addSeconds() on string'
          – Младен Карић
          Nov 12 at 4:02












          can you print out the result of Carbon::parse($auction->get()->end_date) ?
          – James Riady
          Nov 12 at 4:05




          can you print out the result of Carbon::parse($auction->get()->end_date) ?
          – James Riady
          Nov 12 at 4:05












          this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
          – Младен Карић
          Nov 12 at 4:11




          this is dumped result: Carbon @1542171487 {#199 ▼ date: 2018-11-14 04:58:07.0 UTC (+00:00) }
          – Младен Карић
          Nov 12 at 4:11












          So apparently that made it add seconds the right way.
          – Младен Карић
          Nov 12 at 4:13




          So apparently that made it add seconds the right way.
          – Младен Карић
          Nov 12 at 4:13












          I have updated my answer,, Please try it again
          – James Riady
          Nov 12 at 4:13






          I have updated my answer,, Please try it again
          – James Riady
          Nov 12 at 4:13




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255684%2fadding-seconds-with-carbon%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word