0

Using Laravel 5.8 I just want to fetch the work_order_no from table and increment it by 1 and store that value to another variable.

$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;

It display error - Object of class stdClass could not be converted to int

1
  • 3
    Try - intval($statement[0]->work_order_no)+1;. Commented Sep 11, 2019 at 5:54

2 Answers 2

1

Try this.

$statement = DB::table('work_order')->select('work_order_no')->where('id',1)->first();
$nextId = intval($statement->work_order_no) + 1;
$won = $nextId;
Sign up to request clarification or add additional context in comments.

Comments

0

Please try below code. You need to refer $statement using index 0.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.