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

  • We need to know a little more about the structure of your database. How is link in your database the "employer job" and "compagny" ? – Ondrelat Mar 06 '22 at 08: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 – HBilal Khan Mar 06 '22 at 08:58
  • To search in array do you try something like say in this https://stackoverflow.com/questions/38159729/query-laravel-select-wherein-array ? – Ondrelat Mar 06 '22 at 10:11
  • yes I try that, but i dont want to get the exact match I want something which do by LIKE – HBilal Khan Mar 06 '22 at 10:20
  • So i think this is the response https://stackoverflow.com/questions/34329886/laravel-querybuilder-how-to-use-like-in-wherein-function – Ondrelat Mar 06 '22 at 10:24
  • I'm already using this, but here is the problem my database have a skills array and I'm check that with another array – HBilal Khan Mar 06 '22 at 10:48

1 Answers1

0
$companyTags = CompanyJobTag::where('company_id', $company->id)->pluck('name'); //select tags column
$query = EmployerJob::whereJsonContains('skills',$companyTags)->with('user');
shafi M
  • 24
  • 3