【发布时间】:2018-02-20 21:58:00
【问题描述】:
使用复选框,我在表中输入值为 1 的数据。现在,例如,John 有 25 行,值为 1,Michael 15,Maria 10 等...现在,我创建了一个带有链接的引导列表(我将放入附件)并且我希望当我单击 Michael 时向我显示只有 Michael 值为 1 的行的表,对于 John、Maria 等也是如此。
我在那里有更多数据,例如,一些关系,所以当我使用来自纽约的用户登录时,只显示 town_id 为 NY 的名称,这很有效。名字 John、Michael、Maria 没有 ID,所以我无法关联它们,它只是带有变量的列。
路线如下所示:
Route::resource('/statistic', 'StatisticController');
控制器:
public function index()
{
$activists = Activist::where('town_id', Auth::user()->town_id)->get();
return view('statistic.index', compact('activists'));
}
public function show()
{
$activists = Activist::where('town_id', Auth::user()->town_id)->paginate(10);
return view('statistic.show', compact('activists'));
}
index.blade.php:
<ul class="list-group">
<a href="{{ url('statistic/show') }}" class="list-group-item"><span class="badge">{{$activists->where('work_on_computer', 1) ? $activists->where('john', 1)->count() : '0'}}</span> John</a>
<a href="{{ url('statistic/show') }}" class="list-group-item"><span class="badge">{{$activists->where('sticking_posters', 1) ? $activists->where('michael', 1)->count() : '0'}}</span> Michael</a>
<a href="{{ url('statistic/show') }}" class="list-group-item"><span class="badge">{{$activists->where('sharing_flyers', 1) ? $activists->where('maria', 1)->count() : '0'}}</span> Maria</a>
</ul>
现在,当我单击链接时,它会显示整个表格,但我不知道如何仅过滤 John、Michael 或 Maria。对不起,如果我感到困惑。
【问题讨论】:
-
在url中传入user(john) id,然后根据user id获取数据。
-
John 没有 ID,John 只是列名。我仅提及用户 ID 作为示例。
-
你如何在没有关系的情况下对数据库中的记录(哪些数据与哪个用户相关)进行分类?
-
不,我与用户和城镇有关系,这行得通。那是 $activists 变量。也许我把你和提到混淆了。我与 John、Michael、Maria 等列中的 1 值没有关系......因此我不知道如何过滤行。
-
@NenadM,你的路线是什么?
statistic/show,应将 (john) 作为参数。即statistic/show/{slug},是吗?
标签: php mysql twitter-bootstrap laravel