使用复选框,我在表中输入值为 1 的数据。现在,例如,John 有 25 行,值为 1、Michael 15、Maria 10 等...现在,我创建一个带有链接的 Bootstrap 列表(我将放入附件),我希望当我单击 Michael 时,向我显示仅包含 Michael 值为 1 的行的表格,对于 John、Maria 等也是如此。
我在那里有更多数据,例如,一些关系,所以当我使用来自纽约的用户登录时,仅显示town_id为NY的名称,并且这有效。名字 John、Michael、Maria 没有 ID,所以我无法将它们关联起来,它只是带有变量的列。
路线如下所示:
Route::resource('/statistic', 'StatisticController');
Controller :
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>
现在,当我单击链接时,它会显示整个表格,但我不知道如何仅过滤约翰、迈克尔或玛丽亚。抱歉,如果我感到困惑。
最佳答案
我猜您对资源路由感到困惑。它的工作原理是这样的 -
Route::resource('statistic', 'StatisticController');
Actions Handled By Resource Controller
Verb URI Action Route Name
GET /statistic index statistic.index
GET /statistic/create create statistic.create
POST /statistic store statistic.store
GET /statistic/{Id} show statistic.show
GET /statistic/{Id}/edit edit statistic.edit
PUT/PATCH /statistic/{Id} update statistic.update
DELETE /statistic/{Id} destroy statistic.destroy
希望这能帮助您确定进一步的行动。
关于php - Laravel:在多个链接中仅显示某些列值的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46176367/