0

I have a problem of checking whether any values in an array match any values in json column which contains an array with a name. suppose i have an array [25,36,45,52] and json column is {"values": [25,24,15]}. I want to check whether any values in array match any of values in json column in xampp mysql. please provide a better solution of doing this. this image show table structure of my database

i have 4 tables.

  • user
  • profile
  • profile
  • jobs
user table (id,userid)
jobs table (id,user_id,skill_id)
skill table (id,job_id,)
profile table (id,user_id)

now i want to search all jobs that match some or at least one skills. i have tried with this but this is giving all jobs with out skills filtered.

$jobs = Job::with(['user','profile'])->with(['skills' => function($query){
$query->whereJsonContains('skills->skills',[35]);
}])->where('jobs.is_completed',0);

please help me.

2
  • 1
    What have you tried so far? Where are you stuck? Commented Sep 12, 2019 at 15:44
  • i have not tried yet but i am not getting how to do this. please provide some solution Commented Sep 12, 2019 at 15:50

1 Answer 1

1

you can use where Clause easily for example you would like to get rows that match skills 35,54:

$users = DB::table('table')
                -> whereJsonContains('skills->skills', [35,54])
                ->get(); 

for more details about how to querying json column check official docs :

https://laravel.com/docs/5.8/queries#json-where-clauses

Sign up to request clarification or add additional context in comments.

3 Comments

But with multiple values it reaches with multiple values like AND condition but I want search Like OR condition. please provide a solution
if you want complicated where and some advanced filter i advise you using relations with eloquent models feature it's easy to implement
hello, i did some edit in post. can you please help me now.

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.