0

here is my database data design title description skills[]

and request data is tags array which I wanna check with database skills if tags like database skills then return all jobs

$companyTags = CompanyJobTag::where('company_id', $company->id)->get();
$query = EmployerJob::with('user');

$tags = [];
foreach ($companyTags as $key => $tag) {
      array_push($tags, $tag->tag);
}

$query->where(function($q) use($tags){
        for ($i=0; $i < count($tags); $i++) { 
            $q->orWhere('title', 'LIKE', "%{$tags[$i]}%");
        }
});
$jobs = $query->orderByDesc('created_at')
    ->paginate(10);
        
    return response()->json($jobs, 200);

here I can check employer job with companytags array, but empoyerjob also contains jobs skills array so how I can get only that jobs which match with company tags array

here is employerjob table screenshot

6
  • We need to know a little more about the structure of your database. How is link in your database the "employer job" and "compagny" ? Commented Mar 6, 2022 at 8:54
  • employer_jobs table have user_id which user have posted his job, and employee_jobs have title, description and his skills array as shown in the screenshot, and company have company_skills table which have company_id and skill name now I wanna show employers job which skills like with company_tags Commented Mar 6, 2022 at 8:58
  • To search in array do you try something like say in this stackoverflow.com/questions/38159729/… ? Commented Mar 6, 2022 at 10:11
  • yes I try that, but i dont want to get the exact match I want something which do by LIKE Commented Mar 6, 2022 at 10:20
  • So i think this is the response stackoverflow.com/questions/34329886/… Commented Mar 6, 2022 at 10:24

1 Answer 1

0
$companyTags = CompanyJobTag::where('company_id', $company->id)->pluck('name'); //select tags column
$query = EmployerJob::whereJsonContains('skills',$companyTags)->with('user');
Sign up to request clarification or add additional context in comments.

3 Comments

hello bro! this solutions only return the exact match is it possible to use LIKE query here?
use whereJsonContains('skills','like',$companyTags)
actually, I didn't test it

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.