Returning External Array when Retrieving Data with Laravel

Asked

Viewed 124 times

0

I have a column called clube and in one line she has the following {"clube":["Santos"]}, using this form for the data

$clubes = Socios::where('socio', $socio)->select('clube')->get();

He returns to me this way [{"clube":"{"clube":["Santos"]}"}], with an external array called clube, how can I return only what is inside the field in the database ??

  • clube is not the field name ??? and inside the array is clube too? just catch the result $clubes[0]->cluble ???

1 answer

1


Try to use Pluck method native of the Arable, it would look something like:

$clubes = Socios::where('socio', $socio)->pluck('clube');

if you want in array form just add toArray():

$clubes = Socios::where('socio', $socio)->pluck('clube')->toArray();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.