php - Laravel:在多个链接中仅显示某些列值的数据

标签 php mysql twitter-bootstrap laravel

使用复选框,我在表中输入值为 1 的数据。现在,例如,John 有 25 行,值为 1、Michael 15、Maria 10 等...现在,我创建一个带有链接的 Bootstrap 列表(我将放入附件),我希望当我单击 Michael 时,向我显示仅包含 Michael 值为 1 的行的表格,对于 John、Maria 等也是如此。

bootstrap list image

我在那里有更多数据,例如,一些关系,所以当我使用来自纽约的用户登录时,仅显示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/

相关文章:

MySQL:如何锁定表中的各个行?

mysql - 如何对数据进行排序,然后在mysql中对行进行编号?

带有 Bootstrap 标签的 HTML <select>

html - 无法在 Bootstrap Navbar 中看到下拉菜单

PHP 单元 - 未找到类 'PHPUnit_Framework_TestCase'

php - 在 PHP 中执行 Linux 命令

php - MySQL 在事务中重置 AUTO_INCREMENT

php - 整个网站显示为怪异字符

javascript - 如何使用动态插入的 html 元素的 javascript/Jquery 函数调用维护新 id

mysql - 将慢速 LEFT JOIN 转换为 UNION