首页 > 解决方案 > Laravel 5.5 下拉框

问题描述

我是 Laravel 的初学者。我有一个问题,我不知道该怎么做。在 area 的 create.blade.php 中,当我在下拉框中单击某个校区的名称时,下一个下拉菜单会显示下拉菜单中选择的校区的建筑物,第三个下拉菜单会显示其建筑物的楼层数。

我的区域模型 create.blade.php

创建.blade.php

这是我的数据库:

校园

Schema::create('campuses', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->text('address');

        $table->timestamps();
    });

建筑物

Schema::create('buildings', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('campus_id')->unsigned();
        $table->string('name');
        $table->integer('floor');

        $table->foreign('campus_id')->references('id')->on('campuses');

        $table->timestamps();
    });

区域

Schema::create('areas', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('campus_id')->unsigned();
        $table->integer('building_id')->unsigned();
        $table->string('floor');

        $table->foreign('campus_id')->references('id')->on('campuses');
        $table->foreign('building_id')->references('id')->on('buildings');
        $table->timestamps();
    });

数据截图

校园

在此处输入图像描述

建筑物

在此处输入图像描述

领域

在此处输入图像描述

对于添加楼层,在建筑物中它表示为整数。的地板。我只想有一个 for 循环并分配一个数组,以便它可以在区域中选择第一个、第二个、第三个等。谢谢你,如果你能回答这个问题,那将是一个很大的帮助,但我仍然会弄清楚如何做到这一点。

标签: phplaravellaravel-5.5

解决方案


在区域表中添加一列名称作为 floor_val 仅包含整数值,例如 1,2 而不是 1st , 2nd 并在 floor 选项值的下拉列表中使用它。


推荐阅读