如何在 laravel 和 vue js 中使用 2 个或更多条件进行过滤

filterByProject正在工作,但我想添加更多过滤器,即供应商名称。我想要当我按项目和供应商名称过滤它时的结果,它显示两次过滤的过滤结果


  <div class="col-md-12"> 

       <div class="row ml-1"> 

            <span style="color:#424242;font-size:15px; margin-right:5px;">Project:</span>

             <select class="form-control form-control-sm" style="padding:0;

            margin-bottom:5px; height:25px; width:120px;" v-model="filterByProject" 

       @change="filterproject">

               <option>ABC</option>

                </select>

          

         // Supplier name

      <select class="form-control form-control-sm" style="padding:0;

            margin-bottom:5px; height:25px; width:120px;"

               <option>Steel Inc</option>

               <option>L Inc</option>

                </select>


                </div>     

            <div class="card card-primary">

              <div class="card-header"  style="padding-bottom:0px;">

                <h3 class="card-title">Item list&nbsp<span class="fas fa-bookmark"></span>                

                </h3>

              </div>

              <!-- /.card-header -->

              <div class="card-body table-responsive p-0">

                <table class="table table-hover table-bordered table-sm" >

                  <thead>

                    <tr>

                      <th scope="col">#</th>

                      <th scope="col">PO DATE</th>

                      <th scope="col">ITM</th>

                      <th scope="col">PRJ</th>

                      <th scope="col">SUPPLIER</th>

                

                    </tr>

                  </thead>

                  <tbody>

                    <tr v-for="(fetch,count) in item">

                    <td style="height:10px">{{count+1}}</td>

                    <td style="height:10px">{{fetch.po_date}}</td>

                    <td style="height:10px">{{fetch.project}}</td>

                    <td style="height:10px">{{fetch.supplier}}</td>



函数式编程
浏览 128回答 2
2回答

动漫人物

我正在使用此代码进行多个搜索过滤器组合,请看一下,希望它能为您提供一些帮助。我尝试分享我能分享的一切。&nbsp;public function customUserSearchv2(Request $request) {&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the = new Profile();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the = $the->newQuery();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the->leftJoin('tbl1', 'tbl1.id', '=', 'profile.id');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($request->has('thrapyType') && !empty($request->thrapyType)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the->where('profile.services', 'LIKE', '%' . $request->thrapyType . '%');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($request->has('the_name') && !empty($request->the_name)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $full_name = explode(" ", $request->the_name);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $f_name = $full_name[0];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the->where('profile.first_name', 'LIKE', '%' . $f_name . '%');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (count($full_name) > 1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $l_name = $full_name[1];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!empty($l_name)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the->orWhere('profile.last_name', 'LIKE', '%' . $l_name . '%');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($request->has('zipcode') && !empty($request->zipcode)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the->where('profile.office_address_zip', 'LIKE', '%' . $request->zipcode);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //$the->orWhere('profile.secondary_address_zip', 'LIKE', '%' .$request->zipcode);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result = $the->select('profile.*', 'tbl1.name', 'tbl1.email',)->orderBy('profile.id', 'DESC')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->get();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return apiSuccessHandler($result, 200, "SUCCESS", $request, 'Search completed successfully.');&nbsp; &nbsp; &nbsp; &nbsp; } catch (\Exception $e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return apiErrorHandler(500, "INTERNAl SERVER ERROR", $e->getMessage() . ':' . "Server Error Please try after sometime.", $request);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }查看JS<template>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>User Name</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" @keyup="list($event)" name="tname" v-model="tname"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Provider</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select @change="list($event)" name="provider_type" v-model="provider">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value selected>Select Provider</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option v-for="(ins,index) in provider_type.data" :key="index" :value="ins.provider_name">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{ins.provider_name}}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="th-fimg" v-for="(therapist,index) in filterList.data" :key="index"></div>&nbsp;&nbsp;</template>&nbsp; &nbsp; <script>&nbsp; &nbsp; export default{&nbsp; &nbsp; data(){&nbsp; &nbsp; return{&nbsp; &nbsp; &nbsp; filtered_data: [],&nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; methods:{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list(e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let name = "";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name = this.tname;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; provider = this.provider&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$axios&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .get("user/search/v2", {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; headers: apiConst._header,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name:name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; provider: provider&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .then(rec => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rec.data.data.length <= 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.message = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.message = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.filtered_data = rec.data;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .catch(err => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("Filter Error : 207");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }, computed: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filterList() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return this.filtered_data;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; </script>

LEATH

它在 app/Models laravel 8.x 中使用表 PayrollOfficeDeail.php 的模型use Illuminate\Database\Eloquent\Modelclass payroll_office_detail extends Model{&nbsp; &nbsp;public scopeSearch(Builder $query,$fieldName,$fieldVal){&nbsp; &nbsp; &nbsp; &nbsp; return $query->where($fieldName,'=',$fieldVal);&nbsp; &nbsp;}}在控制器文件中添加public function search(Request $request){$searchFieldName=$request->get('field');$payroll_office_detail=payroll_office_detail::query();$payroll_office_detail&nbsp; &nbsp;->leftJoin()//&nbsp; &nbsp;-> ....$payroll_office_detail->search($searchFieldName,'%'.$request->get('q').'%');return $payroll_office_detail->get();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript