1

I have the following query in Laravel :

           $cat_get = DB::table('aimcats as a')
                    ->join('subcat as s', 's.cat_id', '=' , 'a.id')
                    ->where('s.id', $subcat)         
                    ->select('a.id as categ_id')                   
                    ->first();

The vardump for $cat_get is this :

object(stdClass)#392 (1) { ["categ_id"]=> int(502) }

I need to change the 502 to a number without the object to be able to save it in the database.

As of now I'm receiving this error

Object of class stdClass could not be converted to string
1
  • 1
    $cat-get->categ_id? Commented Apr 16, 2020 at 16:10

1 Answer 1

1

I think this code will help you:

$dataToSave = new YourClass;
$dataToSave->categ_id = $cat_get->categ_id;
$dataToSave->save();
Sign up to request clarification or add additional context in comments.

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.