Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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 将记录获取到a<;选择>;在拉威尔5号_Php_Laravel_Twitter Bootstrap_Laravel 5_Eloquent - Fatal编程技术网

Php 将记录获取到a<;选择>;在拉威尔5号

Php 将记录获取到a<;选择>;在拉威尔5号,php,laravel,twitter-bootstrap,laravel-5,eloquent,Php,Laravel,Twitter Bootstrap,Laravel 5,Eloquent,我必须在我的应用程序中需要将外键记录带到select中。 在select中,我需要它显示一盘食物(char)的名称,仅此而已 我有以下表格: 柏拉图 Y 排成一行的rediente(外键所在的位置),如下所示: 柏拉图迁移: <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

我必须在我的应用程序中需要将外键记录带到select中。 在select中,我需要它显示一盘食物(char)的名称,仅此而已

我有以下表格: 柏拉图 Y 排成一行的rediente(外键所在的位置),如下所示:

柏拉图迁移:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePlatosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('platos', function (Blueprint $table) {
            $table->increments('id');
            $table->char('nombre',50);
            $table->double('valor', 8, 2);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('platos');
    }
}
  <?php

    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;

    class CreatePlatoIngredienteTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
        Schema::create('platoIngrediente', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('plato_id');
        $table->foreign('plato_id')->references('id')->on('plato');
        $table->unsignedInteger('plato_id');
        $table->foreign('ingrediente_id')->references('id')->on('ingrediente');
        $table->double('cantidad', 8, 2);
        $table->timestamps();
            });
        }

        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
             Schema::dropIfExists('platoIngrediente');

        }
    }

您需要循环使用$platos

@foreach($platos as $plato)
  <option value=">{{ $plato->nombre }}">{{ $plato->nombre }}</option>
@endofeach
@foreach($plato作为$plato)
{{$plato->nombre}
@内切

您需要循环使用$platos

@foreach($platos as $plato)
  <option value=">{{ $plato->nombre }}">{{ $plato->nombre }}</option>
@endofeach
@foreach($plato作为$plato)
{{$plato->nombre}
@内切
在控制器中:

    public function index(){
        $platoingrediente = PlatoIngrediente::pluck('nombre', 'id');

        return view('platoingrediente/index', compact('platoingrediente'));
    }
在刀片文件中:

  <select class="custom-select">
     <option selected>[ SELECCIONA UN PLATO ]</option>

     @forelse($platoingrediente as $key => $val)
         <option value="{{ $key }}">{{ $val }}</option>
     @empty
     @endforelse
  </select>

[柏拉图之选]
@forelse($PATOINGREDIENTE as$key=>$val)
{{$val}
@空的
@endforelse
在控制器中:

    public function index(){
        $platoingrediente = PlatoIngrediente::pluck('nombre', 'id');

        return view('platoingrediente/index', compact('platoingrediente'));
    }
在刀片文件中:

  <select class="custom-select">
     <option selected>[ SELECCIONA UN PLATO ]</option>

     @forelse($platoingrediente as $key => $val)
         <option value="{{ $key }}">{{ $val }}</option>
     @empty
     @endforelse
  </select>

[柏拉图之选]
@forelse($PATOINGREDIENTE as$key=>$val)
{{$val}
@空的
@endforelse

Undefined variable:plato(0)从代码中,您将“plato ingredients”发送到视图,而不是plato。你介意重复柏拉图还是只想列出唯一的柏拉图?未定义变量:柏拉图(0)从你的代码中,你正在向视图发送“plato Ingredintes”,而不是Platos。你介意重复柏拉图还是只想列出独特的柏拉图?