dryb38654 2017-02-16 02:19
浏览 57
已采纳

如何在链接点击上显示/隐藏字段?

I am using laravel 5.3 I have a responding navigation menu, when I click on domains, it shows all the domains I already have in DB, and then when I click on one of these domains I get the corresponding projects.

Now, I am want that when I click on project it displays all the corresponding data in a table for example. But, this is what I am getting :

this is ProjectController :

  1. public function index(Request $request)
  2. {
  3. $projects1=DB::table('projects')->where('domain_id', '=', 1)->get();
  4. $projects2=DB::table('projects')->where('domain_id', '=', 2)->get();
  5. $projects3=DB::table('projects')->where('domain_id', '=', 3)->get();
  6. return view('projects.index',compact('projects', 'projects1', 'projects2', 'projects3'));
  7. }

and this is index.blade.php :

  1. <div class="nav-side-menu">
  2. <div class="brand">Menu</div>
  3. <i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
  4. <div class="menu-list">
  5. <ul id="menu-content" class="menu-content collapse out">
  6. <li data-toggle="collapse" data-target="#products" class="collapsed active">
  7. <a href="#"><i class="fa fa-gift fa-lg"></i> Domains <span class="arrow"></span> </a>
  8. </li>
  9. <ul class="sub-menu collapse" id="products">
  10. <li data-toggle="collapse" data-target="#domain1_projet" class="collapsed active">
  11. <a href="#"><i class="fa fa-gift fa-lg"></i> Domain 1 <span class="arrow"></span></a>
  12. </li>
  13. <ul class="sub-menu collapse" id="domain1_projet">
  14. @foreach ($projects1 as $key => $project)
  15. <li><a href="#">{{$project->title}}</a></li>
  16. @endforeach
  17. <table class="table table-bordered">
  18. <tr>
  19. <th>No</th>
  20. <th>title</th>
  21. <th>code</th>
  22. <th>domain_id</th>
  23. </tr>
  24. @foreach ($projects1 as $key => $project1)
  25. <tr>
  26. <td>{{ ++$i }}</td>
  27. <td>{{ $project1->title }}</td>
  28. <td>{{ $project1->code }}</td>
  29. <td>{{ $project1->domain_id}}</td>
  30. </tr>
  31. @endforeach
  32. </table>
  33. </ul>
  34. <li data-toggle="collapse" data-target="#domain2_projet" class="collapsed active">
  35. <a href="#"><i class="fa fa-gift fa-lg"></i> Domain 2 <span class="arrow"></span></a>
  36. </li>
  37. <ul class="sub-menu collapse" id="domaine2_projet">
  38. @foreach ($projects2 as $key => $project)
  39. <li><a href="#">{{$project->title}}</a></li>
  40. @endforeach
  41. </ul>
  42. </ul>
  43. </ul>
  44. </div>
  45. </div>

the @if clause I added before table was just to test, but I need to change that. I want to be able to display data of each project not in a manual way. I also want to know how to show and hide the information of each project when clicking on the links. As you can see in index.blade.php, It's because I already know the names of project I did if (($project->intitule)=="Title") and elseif(($project->intitule)=="Project2") But, in fact I have many projects in database. How can I be able to display all the projects and then when I click on one of them, how can get a table containing information of that specific project

展开全部

  • 写回答

1条回答 默认 最新

  • dongzhuang6417 2017-02-16 02:43
    关注

    CONTROLLER

    1. public function index(Request $request)
    2. {
    3. $projects=DB::table('projects')->get();
    4. return view('projects.index',compact('projects'));
    5. }

    VIEW

    1. <div class="nav-side-menu">
    2. <div class="brand">Menu</div>
    3. <i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
    4. <div class="menu-list">
    5. <ul id="menu-content" class="menu-content collapse out">
    6. <li data-toggle="collapse" data-target="#products" class="collapsed active">
    7. <a href="#"><i class="fa fa-gift fa-lg"></i> Domains <span class="arrow"></span> </a>
    8. </li>
    9. <ul class="sub-menu collapse" id="products">
    10. @for ($i = 0; $i < count($projects); $i++)
    11. <li data-toggle="collapse" data-target="#domain1_projet{{$i}}" class="collapsed active">
    12. <a href="#"><i class="fa fa-gift fa-lg"></i> Domain {{$projects[$i]->domain_id}} <span class="arrow"></span></a>
    13. </li>
    14. <ul class="sub-menu collapse" id="domain1_projet{{$i}}">
    15. <li><a href="#">{{$projects[$i]->title}}</a></li>
    16. <table class="table table-bordered">
    17. <tr>
    18. <th>No</th>
    19. <th>title</th>
    20. <th>code</th>
    21. <th>domain_id</th>
    22. </tr>
    23. <tr>
    24. <td>{{ $i }}</td>
    25. <td>{{ $projects[$i]->title }}</td>
    26. <td>{{ $projects[$i]->code }}</td>
    27. <td>{{ $projects[$i]->domain_id}}</td>
    28. </tr>
    29. </table>
    30. </ul>
    31. @endfor
    32. </ul>
    33. </ul>
    34. </div>
    35. </div>

    Try it! and let me know if return errors!

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 学51单片机遇到一点问题
  • ¥15 有人说Java多线程性质是非计算机科班硕士不懂的?
  • ¥15 我如果只想表示节点的结构信息,使用GCN方法不进行训练可以吗
  • ¥15 GPTs营销指令提示词和创建方案
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 本地安装org.Hs.eg.dby一直这样的图片报错如何解决?
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部