我正在使用Laravel Scout和Algolia进行搜索。我在阿尔及利亚有2个索引/表格,job_posts和loyer_profiles。在owner_profiles中,我有2列,company_name和city。我希望能够在v-for
循环中的.vue文件中访问这些列,就像通常使用join
或with(employerprofiles)
一样,因为我已经创建了这种关系。< / p>
如下所示,我想像这样{{jobPost.city}}
和{{jobPost.company_name}}
进行访问,但是我不确定如何在Algolia中执行此操作。
同样,这些列在loyaler_profiles表中。
.vue文件:
<tr v-for="jobPost in jobPosts">
<td>{{jobPost.job_title}}</td>
<td>
<div class="job-company">{{jobPost.company_name}}</div>
</td>
<td><i class="fas fa-map-marker-alt"></i> {{jobPost.city}}</td>
<td>
<div class="full-time">{{jobPost.job_title}}</div>
</td>
<td>
<a href="#" class="apply-job-btn btn btn-radius theme-btn apply-it" data-post-id="457" data-user-id="1" title="Apply this job"><i class="flaticon-paper-plane"></i> Apply</a> </td>
</tr>
我想在控制器中执行类似的操作
$jobPosts = JobPost::with('employerprofile')->search($request->get('q')->get();
但这会带来500错误。
CandidateSearchController.php:
public function search(Request $request)
{
$error = ['error' => 'No results found, please try with different keywords.'];
if($request->has('q')) {
$jobPosts = JobPost::search($request->get('q'))->get();
return $jobPosts->count() ? $jobPosts : $error;
}
return $error;
}