2015-01-21 73 views
0

這是我在PHP條件,我想它轉換爲laravel有如果laravel條件

 <?php 
     if ($DriverDetail['IsActive']=='1') 
     { 
     ?> 
     <span class='account-active'></span> 
     <?php 
     } 
     else 
     { 
     ?> 
     <span class='account-blocked'></span> 
     <?php 
     } 
     ?> 

我試着用

{{ $DriverDetail['IsActive'] }} 

和串連內{{}}

<span class='account-blocked'></span>

但是,哪種方法能讓laravel中的條件等於我的php代碼

回答

1

嘗試:

<span class='{{ $DriverDetail['IsActive'] ? 'account-active' : 'account-blocked' }}'></span> 

或者,如果你想分離的整個跨度:

{{ $DriverDetail['IsActive'] ? "<span class='account-active'></span>" : "<span class='account-blocked'></span>" }} 

這是使用三元操作符(文檔here)。基本上,任何計算爲布爾值true的值都會輸出第一個表達式(在'?'後面),否則會輸出第二個表達式(在':'後面)。在這種情況下,字符串'1'或甚至數字1的計算結果爲布爾值true,因此三元運算符將評估爲「true」表達式('account-active')。隱式布爾轉換涵蓋文檔here

+0

大,可以請你解釋它是如何檢查的價值'1 '? – AngularAngularAngular 2015-01-21 07:48:49

+0

@Chennai我已經更新了答案以提供解釋。 – patricus 2015-01-21 07:56:29

1

試試這個...

@if (count($records) === 1) 
    I have one record! 
@elseif (count($records) > 1) 
    I have multiple records! 
@else 
    I don't have any records! 
@endif 
+0

@extends(「template/index」)??? – AngularAngularAngular 2015-01-21 07:49:24

0

隨着刀片模板系統,明確的方法是:

@if ($DriverDetail['IsActive']) 
    <span class='account-active'></span> 
@else 
    <span class='account-blocked'></span> 
@endif