0

I have one database query which returns collection, i want to fetch the value instead of fetching collection or array, please help me to achieve this thing

$type=DB::table('users')->where('id',$value)->pluck('role')->toArray();

Actual Result : ['admin'] //array

Expected Result : $type='admin'

3
  • 1
    Why would you expect $type to be in the result, where does that come from? ->toArray() returns ... an array, have you tried echoing its first(only) element? Commented Jan 20, 2022 at 7:10
  • ->toArray()[0] I presume. Commented Jan 20, 2022 at 7:11
  • @brombeer, first() returns string, Thanks Commented Jan 20, 2022 at 7:26

1 Answer 1

1

You can use implode...

implode("|",$type);
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.