I am returning an array using query builder, and I want to access its object only, not the whole array.
Here is the query
$data = ($request->props[0]);
$index = DB::table('produits')
->select('sous_categorie_id')
->where('product_type', 'like', $data)
->get();
return $index;
The results that I am getting:
[{
"sous_categorie_id":7
}]
What am trying to get:
[
7,
]
I tried Model Query but I am not so familiar with it, so I have hit a wall here so I need help, Thanks in advance.
>Solution :
You can use the pluck() method in Laravel.
$data = $request->props[0];
$index = DB::table('produits')
->select('sous_categorie_id')
->where('product_type', 'like', $data)
->get()
->pluck('sous_categorie_id');
return $index;