doumao8803 2018-06-20 00:15
浏览 23
已采纳

Laravel Eloquent不会显示查询

I have successfully displayed data from one table in one part of my application, but the data won't display in another part. I want to include the Record for the winning team of that year. My View returns nothing when it should return an integer. I am using laravel 5.6.

Controller

$seasonOneWins=gameData::where('homeTeam', '81-North Stars')
                      ->where('homeWin', '1')
                      ->where('year', '2016'); 

View:

@if($seasonOneWins)
   @foreach($seasonOneWins as $seasonOneWin)
     <p>{!!$seasonOneWin!!}<p>
   @endforeach
@endif

I can't get anything to display in between the foreach's. I assume this means that my formula is suggesting that there is nothing that meets those requirements when I know there is.

  • 写回答

2条回答 默认 最新

  • douyinjiao9351 2018-06-20 13:22
    关注

    So this was a misunderstanding. I kept trying to use count() on a foreach, which caused an error. I had the wrong syntax in my view, instead of the foreach() I should have coded:

    View

       <p>   {!!$seasonOneWins!!}<p>
    

    Controller

       $seasonOneWins=GameData::where('team', '81 North Stars')
       ->where('win', '1')
       ->where('year', 2016)
       ->count();  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入