简体   繁体   English

使用jQuery和laravel填充选择的正确方法是什么?

[英]what is the correct method to fill select use jQuery and laravel?

I have a form for adding Salaries, in this form there is select Fonction_id foreign key from table function in table Salaries (belongsTo relation between them), I want to fill this select, knowing that I use laravel and jquery, what is the good method to do.我有一个添加Salaries的表格,在这个表格里有select Fonction_id外键 from table function in table Salaries(belongsTo它们之间的关系),我想填这个select,知道我用的是laravel和jquery,有什么好方法去做。

<div class="form-group col-md-3">
     <select class="form-control" name="fonction_id">
          <option></option>
          <option> fonction_id </option>
      </select>
</div>

It do not need to jquery.Do it as bellow:它不需要 jquery.Do 如下:

First select your objects from database in controller and pass it from controller to view by compact like this:首先从控制器中的数据库中选择您的对象,然后将其从控制器传递给像这样的compact视图:

$models = Yourmodel::All();
return view('yourview',compact('models');

And in your view render it in foreach as this:在你看来,在 foreach 中渲染它是这样的:

  <select>
      @foreach($models as $model)
        <option>{{$model->yourfield}}</option>@endforeach </select>         

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM