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);
}
php laravel date timestamp
add a comment |
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);
}
php laravel date timestamp
add a comment |
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);
}
php laravel date timestamp
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
php laravel date timestamp
asked Nov 12 at 3:42
Младен Карић
137
137
add a comment |
add a comment |
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');
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 ofCarbon::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
|
show 1 more comment
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');
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 ofCarbon::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
|
show 1 more comment
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');
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 ofCarbon::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
|
show 1 more comment
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');
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');
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 ofCarbon::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
|
show 1 more comment
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 ofCarbon::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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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