0

My select query is returning an array... but I would like for it to return an object

PHP:

$language = DB::select(select query here);

I tried adding ->get() after but it seems that I can't add that to an array.

2 Answers 2

6

Yes, It's supposed to return an array of stdClass objects, no need for ->get when usind DB:select to run raw MySql code.

If you are selecting a row with the raw sql, then you can access the object for that row as $language[0], else you have to loop through it.

Sign up to request clarification or add additional context in comments.

Comments

2

->get() returns a collection. If you just want to get one object, use ->first() instead.

See the query builder documentation under "Retrieving A Single Row / Column From A Table" for more details.

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.