如何在Laravel 5.6中使用province_id打印省名

时间:2018-08-07 18:23:36

标签: php mysql laravel

我正在使用laravel 5.6开发应用程序。在我的应用程序中,我有三个表,分别是城镇,并且我的模型与每个模型都有以下关系,

<main>
  <input id="tab1" type="radio" name="tabs" checked>
  <label for="tab1">Small Business</label>
  <input id="tab2" type="radio" name="tabs">
  <label for="tab2">Medium Business</label>
  <input id="tab3" type="radio" name="tabs">
  <label for="tab3">Large Business</label>
  <section id="content1">
    <p>
      TEST
    </p>
    <p>
      Brisket meatball turkey short loin boudin leberkas meatloaf chuck andouille pork loin pastrami spare ribs pancetta rump. Frankfurter corned beef beef tenderloin short loin meatloaf swine ground round venison.
    </p>
  </section>
  <section id="content2">
    <p>
      Bacon ipsum dolor sit amet landjaeger sausage brisket, jerky drumstick fatback boudin ball tip turducken. Pork belly meatball t-bone bresaola tail filet mignon kevin turkey ribeye shank flank doner cow kielbasa shankle. Pig swine chicken hamburger, tenderloin
      turkey rump ball tip sirloin frankfurter meatloaf boudin brisket ham hock. Hamburger venison brisket tri-tip andouille pork belly ball tip short ribs biltong meatball chuck. Pork chop ribeye tail short ribs, beef hamburger meatball kielbasa rump
      corned beef porchetta landjaeger flank. Doner rump frankfurter meatball meatloaf, cow kevin pork pork loin venison fatback spare ribs salami beef ribs.
    </p>
    <p>
      Jerky jowl pork chop tongue, kielbasa shank venison. Capicola shank pig ribeye leberkas filet mignon brisket beef kevin tenderloin porchetta. Capicola fatback venison shank kielbasa, drumstick ribeye landjaeger beef kevin tail meatball pastrami prosciutto
      pancetta. Tail kevin spare ribs ground round ham ham hock brisket shoulder. Corned beef tri-tip leberkas flank sausage ham hock filet mignon beef ribs pancetta turkey.
    </p>
  </section>
  <section id="content3">
    <p>
      Bacon ipsum dolor sit amet beef venison beef ribs kielbasa. Sausage pig leberkas, t-bone sirloin shoulder bresaola. Frankfurter rump porchetta ham. Pork belly prosciutto brisket meatloaf short ribs.
    </p>
    <p>
      Brisket meatball turkey short loin boudin leberkas meatloaf chuck andouille pork loin pastrami spare ribs pancetta rump. Frankfurter corned beef beef tenderloin short loin meatloaf swine ground round venison.
    </p>
  </section>
  </section>
</main>

现在我可以使用Controller中的Towns表获取数据,

 Province
    public function districts()
            {
                return $this->hasMany(District::class);
            }





 District
        public function province()
            {
                return $this->belongsTo(Province::class);
            }

Town
 public function district()
    {
        return $this->belongsTo(District::class);
    }

和刀片文件中的下拉选择输入

 $town_list = DB::table('towns')

                     ->groupBy('province_id')
                     ->get();

现在我可以在我的选择输入中看到province_id,但是我需要在选择输入中打印省份名称, 我的表格结构,

<div class="form-group">
            <label for="exampleFormControlSelect1">Province</label>
        <select name="province_id" id="province_id" class="form-control input dynamic" data-dependent="district_id" >
            <option value="">Select Province</option>
            @foreach($town_list as $town)
            <option value="{{$town->province_id}}">{{$town->province_id}}</option>
            @endforeach
        </select>
        </div>

该怎么办?

1 个答案:

答案 0 :(得分:1)

尝试使用紧急加载:

await

现在您可以在视图中循环并调用省名称。