down_load1117 2014-12-05 01:05
浏览 50
已采纳

将布尔值传递给Laravel中的视图

What I try to do:

I try to pass a boolean to my view to to check if it is true or not. If it is set to true, I want to add a class. I use Laravel. Actually, here is my situation:

  • The .red class is added to all rows
  • $finances->depense always return 1 even if it says 0 in the database

Here is my code:

index.blade.php

@foreach($finances as $finance)
    @if ($finance->depense = 1)
        <tr class="red">
    @elseif ($finance->depense = 0) 
        <tr>
    @endif
            <td><a href="{{ URL::to('finances/' . $finance->id) }}">{{$finance->description}}</a></td>
            <td>{{ $finance->depense }}</td>
            <td>{{ $finance->prix }}</td>
            <td>{{ $finance->tps }}</td>
            <td>{{ $finance->tvq }}</td>
            <td>{{ $finance->grandtotal }}</td>
        </tr>
@endforeach

FinancesController.php

public function index()
{
    $finances = Finance::all();
    return View::make('finances.index')->withFinances($finances);
}

What is wrong?

  • 写回答

2条回答 默认 最新

  • douhan9748 2014-12-05 01:17
    关注

    The answer was finaly very simple..

    Instead of

    @if ($finance->depense = 1)
        <tr class="red">
    @elseif ($finance->depense = 0) 
        <tr>
    @endif
    

    I changed the = to ==

    @if ($finance->depense == 1)
        <tr class="red">
    @else 
        <tr>
    @endif
    

    Don't forget to use double equal to compare.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件