Php Laravel:动态选项卡不';不显示正确的数据?
我尝试在laravel中使用动态标签,我对它有点陌生。我在里面呆了两天 我有两个变量可以从mysql中的表中获取数据Php Laravel:动态选项卡不';不显示正确的数据?,php,html,laravel,tabs,Php,Html,Laravel,Tabs,我尝试在laravel中使用动态标签,我对它有点陌生。我在里面呆了两天 我有两个变量可以从mysql中的表中获取数据 $stations = Station::select('id', 'name')->get(); // return $staions; $queues = Queue::withTrashed() ->oldest() ->get(); // return $queues; $schedul
$stations = Station::select('id', 'name')->get();
// return $staions;
$queues = Queue::withTrashed()
->oldest()
->get();
// return $queues;
$schedules
中的数据:
[
{
"id":1,
"name":"siinay"
},
{
"id":2,
"name":"jigjiga"
},
{
"id":3,
"name":"Idaacada"
},
{
"id":4,
"name":"Xero Awr"
}
]
以及$queues
中的数据:
[
{
"id":1,
"name":"siinay"
},
{
"id":2,
"name":"jigjiga"
},
{
"id":3,
"name":"Idaacada"
},
{
"id":4,
"name":"Xero Awr"
}
]
因此,问题出现在动态选项卡中:我想在导航选项卡中显示站点名称,选项卡内容中显示队列。所以我就这样做了
<ul class="nav nav-tabs">
@forelse ($stations as $station)
<li >
<a data-toggle="tab" href="#tab-{{ $station->id }}" >
{!! $station->name !!}
</a>
</li>
@empty
@endforelse
</ul>
<div style="margin-top: 15%" class="tab-content">
@foreach($queues as $queue)
@if($queue)
<div id="tab-{{ $queue->station_id}}" class="tab-pane fade">
<p>{!! $queue->bus_number !!}</p>
</div>
@else
<div>empty</div>
@endif
@endforeach
</div>
@forelse($stations as$station)
-
@空的
@endforelse
@foreach($queues作为$queue)
@如果($队列)
{!!$queue->总线号!!}
@否则
空的
@恩迪夫
@endforeach
当我运行上述代码时,
仅显示每个选项的最后一个队列总线号。每个车站排队的人都是最老的,这与第一个相反。尝试以下操作以获取收藏:
$queues = Queue::withTrashed()
->orderBy('id', 'desc')
->get();
在视图中(简化):
@foreach($stations作为$station)
-
@endforeach
@foreach($queues作为$queue)
{{$queue->bus_number}
@endforeach
无需检查是否为空。每一个都是一个表记录。除非你想查看公共汽车号码或车站id。最旧的确实是最旧的,它与第一个相反。尝试以下操作以获取收藏:
$queues = Queue::withTrashed()
->orderBy('id', 'desc')
->get();
在视图中(简化):
@foreach($stations作为$station)
-
@endforeach
@foreach($queues作为$queue)
{{$queue->bus_number}
@endforeach
无需检查是否为空。每一个都是一个表记录。除非您想检查公交车号或车站id。如上图所示,我正在从控制器获取正确的数据,但我认为问题在于视图选项卡中的,我将重写您的代码,检查并查看发生了什么。我检查了,但结果是一样的。从表面上看,它只是先循环然后存在。这就是为什么它显示每个站点的总线号。正如上图所示,我从控制器获得了正确的数据,但我认为问题出在视图选项卡中,我将重写您的代码,检查它并查看发生了什么。我检查了,但它是一样的。从表面上看,它只是先循环然后存在。这就是为什么它会显示每个车站的公交车号。