亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Laravel 中使用兩個輸入框從數據庫中過濾數據

如何在 Laravel 中使用兩個輸入框從數據庫中過濾數據

PHP
尚方寶劍之說 2023-06-24 15:31:45
我需要有自己的自定義設計,我可以在其中添加 @foreach 并自定義設計,我不知道該怎么做,我嘗試了很多方法但失敗了。有人可以建議我一個解決方案,或者建議我遵循任何教程,我可以根據需要將過濾后的數據加載到我的視圖中。這是我的stores.blade.php搜索字段和表格所在的位置,? ?<h3 align="center">Store Locator</h3>? ? ? ? <div class="row">? ? ? ? ? ? <div class="col-md-4"></div>? ? ? ? ? ? <div class="col-md-4">? ? ? ? ? ? ? ? <div class="form-group">? ? ? ? ? ? ? ? ? ? <select name="filter_district" id="filter_district" class="form-control" required>? ? ? ? ? ? ? ? ? ? ? ? <option value="">Select Distric</option>? ? ? ? ? ? ? ? ? ? ? ? @foreach ($district_name as $district)? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<option value="{{ $district->district }}">{{ $district->district }}</option>? ? ? ? ? ? ? ? ? ? ? ? @endforeach? ? ? ? ? ? ? ? ? ? </select>? ? ? ? ? ? ? ? </div>? ? ? ? ? ? ? ? <div class="form-group">? ? ? ? ? ? ? ? ? ? <select name="filter_outlet" id="filter_outlet" class="form-control" required>? ? ? ? ? ? ? ? ? ? ? ?<option value="">Select Outlet</option>? ? ? ? ? ? ? ? ? ? ? ? @foreach($outlet_name as $country)? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="{{ $country->outlet }}">{{ $country->outlet }}</option>? ? ? ? ? ? ? ? ? ? ? ? @endforeach? ? ? ? ? ? ? ? ? ? </select>? ? ? ? ? ? ? ? </div>? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? <div class="form-group" align="center">? ? ? ? ? ? ? ? ? ? <button type="button" name="filter" id="filter" class="btn form-submit">Filter</button>? ? ? ? ? ? ? ? ? ? <button type="button" name="reset" id="reset" class="btn form-submit">Reset</button>? ? ? ? ? ? ? ? </div>? ? ? ? ? ? </div>? ? ? ? ? ? <div class="col-md-4"></div>? ? ? ? </div>? ? ? ? <br />
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

通過 eager load 發送結果時,需要包含商店的區域名稱。因此,在您的商店模型中,創建一個belongsTo關系


public function district() {

    return $this->belongsTo('App\District', 'district');

}

所以當你發送結果時,你可以寫


$data = Store::select('id','outlet', 'province', 'district', 'no1', 'no2', 'no3', 'address')

     ->where('district', $request->filter_district)

     ->where('outlet', $request->filter_outlet)

     ->with(['district'])

     ->get();


查看完整回答
反對 回復 2023-06-24
  • 1 回答
  • 0 關注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號