0

I have a json object

'developer' => 
  array (
    'count' => 1,
    'docPosition' => 100,
    'countCv' => 1,
    'weight' => '0.077',
  ),
  'Software Engineer' => 
  array (
    'count' => 4,
    'docPosition' => 716,
    'countCv' => 4,
    'weight' => '0.308',
  ),
  'engineer' => 
  array (
    'count' => 5,
    'docPosition' => 725,
    'countCv' => 5,
    'weight' => '0.385',
  ),
  'Software Development Engineer' => 
  array (
    'count' => 1,
    'docPosition' => 1272,
    'countCv' => 1,
    'weight' => '0.077',
  ),
  'Development Engineer' => 
  array (
    'count' => 1,
    'docPosition' => 1281,
    'countCv' => 1,
    'weight' => '0.077',
  ),
  'Contract' => 
  array (
    'count' => 1,
    'docPosition' => 1303,
    'countCv' => 1,
    'weight' => '0.077',
  ),
)

I want to get the keys of the object (developer, Software Engineer, engineer, etc) and use them to search the db for matches that are in a field called Industry that is an array. I am unsure about the following.

  1. How to get the keys on the object and turn it into an array.
  2. Search my db for any matches between the array I created and the array in the field Industry.

I have searched google and stack and have not found anything helpful. Any ideas or strategies would be appreciated.

3
  • What SQL you are using? array is a vendor-specific column type. iirc eloquent just converts arrays to strings to persist it in the db. Commented May 15, 2017 at 17:10
  • @AlexBlex I am using mySql Commented May 15, 2017 at 17:15
  • mysql does not have array types. Commented May 15, 2017 at 17:19

1 Answer 1

1

You can make that json object into a Collection :

$collection=collect(json_decode($yourObject);

And get the keys :

$keys = $collection->keys();

And you can retrieve from your data like this

$data = collect($yourData);
$results = $keys->each(function($key){
             $data->only($key);
             //do your logic with it
});

you can learn more about it here : Laravel Collection

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.