michal michal - 1 year ago 93
JSON Question

Laravel json convert to array only number PHP

I have code:

return $getId = Permission::select('id')->get();

This code returned me:


I want to query returned the records in the form of:


How can I do this? I tried to use
, but it's not work I also tried to use a foreach loop, but the result was the same. I'm doing this because I want to compare the two tables using
, but still I have error:

array_diff(): Argument #1 is not an array

Argument 1
is variable

Answer Source

You want to use pluck() and toArray() methods:

return $getId = Permission::pluck('id')->toArray();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download