在 laravel 中搜索列名以获取行

search for column name in laravel to get rows

我有两个table(工作,技能) 技能 职位

我想按 laravel 按技能搜索工作。当我写 html -> 1-(搜索列名) 2-(获取该列等于 1 的行) 3-(获得 job_id(table 工作)= job_id(table 技能)

的工作

我的代码

$search_name = $request->input('search');
$skillscolumns =  DB::getSchemaBuilder()->getColumnListing('skills');

//1
$query = Skill::select('*');
foreach($skillscolumns as $column) {
   $query->where($column, '=', $search_name);
}
$searchedColumn = $query->get();

//2
foreach ($searchedColumn  as  $value) {
    $skillRows = collect($value)->filter(function ($value){ return $value === 1;})->get();
}

//3
foreach ( $skillRows  as  $value) {
    $wantedJobs = Job::where('job_id',$value->job_id)->get();
}
$jobs = [];
if(in_array($request->search, (new Skill)->getFillable())){
    $ids = Skill::where($request->search, true)->get()->pluck('job_id');
    if($ids){
        $jobs = Job::find($ids);
    }
}