You need flatten method:
Feb 11, 2021
6
Level 1
get Value Only from laravel Collection result
I have the following query(the actual query is too long and contains DB::raw so the query here is for question only)
$query=DB::table(DB::raw('users@KVDBLINK'))->select('name','id','email')->limit(2)->get();
the result is
[ {"name":"Dayle","id":1,"email":"dayle213@gmail.com"}, {"name":"John","id":2,"email":"[email protected]"} ]
but i want the result like
[ {"Dayle",1,"dayle213@gmail.com"}, {"John",2,"[email protected]"} ]
NB: this might not be the right place to ask but in stackoverflow it seems i didnot get much help. I need array of values so i can insert in bulk .
Level 27
@seyidtakele@gmail.com You could use transform():
$result->transform(fn($user) => [$user->name, $user->id, $user->email])
1 like
Please or to participate in this conversation.