Form中的Foreach ::在Laravel 4中选择

0 laravel-4

我尝试使用Laravel的帮助程序来处理一个变量,但它会发生错误,当我对html标记执行相同操作时,它可以正常工作.

{{ Form::select('categoria', array(
        @foreach($enlaceid as $categoria) 
          $categoria->id => $categoria->nombre  {{-- I tryed too with englobing with {{ }}
      )) }} 
      @endforeach

    <select name="categoria">
        @foreach($enlaceid as $categoria) 
        <option value= " {{ $categoria->id }} "> {{$categoria->nombre}} </option>
        @endforeach
    </select>
Run Code Online (Sandbox Code Playgroud)

Gar*_*ine 5

使用该lists()方法并将其传递给您的Form::select()方法.像这样:

$categories = Category::lists('name', 'id');
Run Code Online (Sandbox Code Playgroud)

在你看来:

{{ Form::select('category_id', $categories) }}
Run Code Online (Sandbox Code Playgroud)