2 回答
TA贡献1815条经验 获得超10个赞
我正在使用此代码进行多个搜索过滤器组合,请看一下,希望它能为您提供一些帮助。我尝试分享我能分享的一切。
public function customUserSearchv2(Request $request) {
try {
$the = new Profile();
$the = $the->newQuery();
$the->leftJoin('tbl1', 'tbl1.id', '=', 'profile.id');
if ($request->has('thrapyType') && !empty($request->thrapyType)) {
$the->where('profile.services', 'LIKE', '%' . $request->thrapyType . '%');
}
if ($request->has('the_name') && !empty($request->the_name)) {
$full_name = explode(" ", $request->the_name);
$f_name = $full_name[0];
$the->where('profile.first_name', 'LIKE', '%' . $f_name . '%');
if (count($full_name) > 1) {
$l_name = $full_name[1];
if (!empty($l_name)) {
$the->orWhere('profile.last_name', 'LIKE', '%' . $l_name . '%');
}
}
}
if ($request->has('zipcode') && !empty($request->zipcode)) {
$the->where('profile.office_address_zip', 'LIKE', '%' . $request->zipcode);
//$the->orWhere('profile.secondary_address_zip', 'LIKE', '%' .$request->zipcode);
}
$result = $the->select('profile.*', 'tbl1.name', 'tbl1.email',)->orderBy('profile.id', 'DESC')
->get();
return apiSuccessHandler($result, 200, "SUCCESS", $request, 'Search completed successfully.');
} catch (\Exception $e) {
return apiErrorHandler(500, "INTERNAl SERVER ERROR", $e->getMessage() . ':' . "Server Error Please try after sometime.", $request);
}
}
查看JS
<template>
<label>User Name</label>
<input type="text" @keyup="list($event)" name="tname" v-model="tname"/>
<label>Provider</label>
<select @change="list($event)" name="provider_type" v-model="provider">
<option value selected>Select Provider</option>
<option v-for="(ins,index) in provider_type.data" :key="index" :value="ins.provider_name">
{{ins.provider_name}}
</option>
</select>
<div class="th-fimg" v-for="(therapist,index) in filterList.data" :key="index"></div>
</template>
<script>
export default{
data(){
return{
filtered_data: [],
}
}
methods:{
list(e) {
let name = "";
name = this.tname;
provider = this.provider
this.$axios
.get("user/search/v2", {
headers: apiConst._header,
params: {
name:name,
provider: provider
}
})
.then(rec => {
if (rec.data.data.length <= 0) {
this.message = true;
} else {
this.message = false;
}
this.filtered_data = rec.data;
})
.catch(err => {
console.log("Filter Error : 207");
});
}
}, computed: {
filterList() {
return this.filtered_data;
}
}
}
</script>
TA贡献1936条经验 获得超6个赞
它在 app/Models laravel 8.x 中使用表 PayrollOfficeDeail.php 的模型
use Illuminate\Database\Eloquent\Model
class payroll_office_detail extends Model{
public scopeSearch(Builder $query,$fieldName,$fieldVal){
return $query->where($fieldName,'=',$fieldVal);
}
}
在控制器文件中添加
public function search(Request $request){
$searchFieldName=$request->get('field');
$payroll_office_detail=payroll_office_detail::query();
$payroll_office_detail
->leftJoin()
// -> ....
$payroll_office_detail->search($searchFieldName,'%'.$request->get('q').'%');
return $payroll_office_detail->get();
}
添加回答
举报