Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Laravel中的两个输入框过滤数据库中的数据_Php_Ajax_Laravel_Laravel 5_Eloquent - Fatal编程技术网

Php 如何使用Laravel中的两个输入框过滤数据库中的数据

Php 如何使用Laravel中的两个输入框过滤数据库中的数据,php,ajax,laravel,laravel-5,eloquent,Php,Ajax,Laravel,Laravel 5,Eloquent,我只是跟着一个YouTube教程,在那里,导师做了一些与我想要的相似的事情 教程链接: 在本教程中,导师使用Datatable加载所有数据并显示所有过滤结果 我需要有自己的定制设计,在这里我可以添加@foreach并定制设计, 我不知道我该怎么做我尝试了很多方法但都失败了 有没有人能为我推荐一个解决方案,或者给我推荐一些教程,让我可以根据需要将过滤后的数据加载到视图中 这是我的stores.blade.php,搜索字段和表都在这里 <h3 align="center&q

我只是跟着一个YouTube教程,在那里,导师做了一些与我想要的相似的事情 教程链接:

在本教程中,导师使用Datatable加载所有数据并显示所有过滤结果

我需要有自己的定制设计,在这里我可以添加@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 />
        <div class="table-responsive">
            <table id="store_data" class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Outlet</th>
                        <th>Province</th>
                        <th>District</th>
                        <th>Number 1</th>
                        <th>Number 2</th>
                        <th>Number 3</th>
                        <th>Address</th>
                    </tr>
                </thead>
            </table>
        </div>
这是我的模型

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Store extends Model
{
    protected $table = 'stores';
}
这是我的
数据库

这就是我的ui的样子

我只是想知道一种方法,如何显示从数据库加载到表中的结果,并将其加载到foreach中,以便在搜索功能正常工作的情况下,以我想要的方式进行设计,
有人能帮我一下吗,或者请建议我一些可以解决这个问题的方法,

当您通过“急切加载”发送结果时,您需要包括门店的地区名称。因此,在您的商店模型中,创建一个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();
Route::resource('/store-locatorr', 'StoreLocatorController');
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();