未定义变量 $districts,但 $provinces 和 $regcies 可以工作
我不需要该模型,因为我看到 $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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要将它们全部作为第二个参数的一个数组发送:
I think you need to send all of them as one array on the second argument: