如何在 Laravel 或 Php 中手动增加获取的数据值?

How to increment fetched data value manually in Laravel or Php?

使用Laravel 5.8 我只想从 table 获取 work_order_no 并将其递增 1 并将该值存储到另一个变量。

$statement = DB::select('select work_order_no from work_order where id = 1');
//$won = $won_id->work_order_no+1;
$nextId = intval($statement[0])+1;
$won = $nextId;

显示错误- class stdClass 的对象无法转换为 int

请尝试以下代码。您需要使用索引 0 引用 $statement

        $currentId = $statement[0]->work_order_no ;
        $nextId = $currentId + 1;
        echo $nextId;  //prints 2 if $currentId is 1

试试这个。

$statement = DB::table('work_order')->select('work_order_no')->where('id',1)->first();
$nextId = intval($statement->work_order_no) + 1;
$won = $nextId;