未定义变量 $districts,但 $provinces 和 $regcies 可以工作

发布于 2025-01-13 03:40:20 字数 2826 浏览 0 评论 0原文

我不需要该模型,因为我看到 $province$regcies 正在工作,但是 $districts$villages > 未定义。

控制器

class LocationController extends Controller
{
    public function index()
    {
        $provinces = DB::table('reg_provinces')->pluck('name');
        $regencies = DB::table('reg_regencies')->pluck('name');
        $districts = DB::table('reg_districts')->pluck('name');
        $villages = DB::table('reg_villages')->pluck('name');

        return view('index',
            ['provinces' => $provinces],
            ['regencies' => $regencies],
            ['districts' => $districts],
            ['villages' => $villages],
        );
    }
}

视图

     <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select Province
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($provinces as $province)
            <li class="dropdown-item">{{ $province }}</li>
          @endforeach
        </ul>
      </div>

      <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select City
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($regencies as $regency)
            <li class="dropdown-item">{{ $regency }}</li>
          @endforeach
        </ul>
      </div>

      <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select District
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($districts as $district)
            <li class="dropdown-item">{{ $district }}</li>
          @endforeach
        </ul>
      </div>

      <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select Subdistrict
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($villages as $village)
            <li class="dropdown-item">{{ $village }}</li>
          @endforeach
        </ul>
      </div>

I do not need the model as I see $province and $regencies working, but the $districts and $villages are not defined.

Controller

class LocationController extends Controller
{
    public function index()
    {
        $provinces = DB::table('reg_provinces')->pluck('name');
        $regencies = DB::table('reg_regencies')->pluck('name');
        $districts = DB::table('reg_districts')->pluck('name');
        $villages = DB::table('reg_villages')->pluck('name');

        return view('index',
            ['provinces' => $provinces],
            ['regencies' => $regencies],
            ['districts' => $districts],
            ['villages' => $villages],
        );
    }
}

View

     <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select Province
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($provinces as $province)
            <li class="dropdown-item">{{ $province }}</li>
          @endforeach
        </ul>
      </div>

      <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select City
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($regencies as $regency)
            <li class="dropdown-item">{{ $regency }}</li>
          @endforeach
        </ul>
      </div>

      <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select District
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($districts as $district)
            <li class="dropdown-item">{{ $district }}</li>
          @endforeach
        </ul>
      </div>

      <div class="dropend mb-3">
        <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
          Select Subdistrict
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
          @foreach ($villages as $village)
            <li class="dropdown-item">{{ $village }}</li>
          @endforeach
        </ul>
      </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2025-01-20 03:40:20

我认为您需要将它们全部作为第二个参数的一个数组发送:

class LocationController extends Controller
{
    public function index()
    {
        $provinces = DB::table('reg_provinces')->pluck('name');
        $regencies = DB::table('reg_regencies')->pluck('name');
        $districts = DB::table('reg_districts')->pluck('name');
        $villages = DB::table('reg_villages')->pluck('name');

        return view('index',
            [
              'provinces' => $provinces,
              'regencies' => $regencies,
              'districts' => $districts,
              'villages' => $villages
             ],
        );
    }
}

I think you need to send all of them as one array on the second argument:

class LocationController extends Controller
{
    public function index()
    {
        $provinces = DB::table('reg_provinces')->pluck('name');
        $regencies = DB::table('reg_regencies')->pluck('name');
        $districts = DB::table('reg_districts')->pluck('name');
        $villages = DB::table('reg_villages')->pluck('name');

        return view('index',
            [
              'provinces' => $provinces,
              'regencies' => $regencies,
              'districts' => $districts,
              'villages' => $villages
             ],
        );
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文