用碳增加秒数

Мла*_*рић 3 php timestamp date laravel

这个想法是我需要通过这个模型从 Auction 中获取 end_date,该模型位于数据库中,采用 MySQL 时间戳格式(如果重要,我使用 phpmyadmin,例如 2018-11-14 04:58:07)。因此,当我获得 end_date 时,想法是通过 Carbon addSeconds() 函数将其增加几秒(例如 10 秒),然后再次将其写入数据库。这是完成的控制器和我的拍卖模型。发生的情况是我收到 FatalThrowableError 'Call to a member function addSeconds() on integer'。我玩了很多,似乎找不到 secs2 变量的正确格式。

拍卖.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;
}
Run Code Online (Sandbox Code Playgroud)

拍卖控制器.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);
}
Run Code Online (Sandbox Code Playgroud)

Jam*_*ady 10

如果要使用addSeconds方法,则不能先将时间转换为数字.. 例如:

Carbon::parse($auction->get()->end_date)
      ->addSeconds(120)
      ->format('H:i:s');
Run Code Online (Sandbox Code Playgroud)