Laravel 8 If 語句

2021-07-17 16:47 更新

您可以使用 @if@elseif , @else@endif 指令構(gòu)造 if 語句。這些指令功能與它們所對應的 PHP 語句完全一致:

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

為了方便, Blade 還提供了一個 @unless 指令:

@unless (Auth::check())
    You are not signed in.
@endunless 

除了已經(jīng)討論過了的條件指令外, @isset@empty 指令亦可作為它們所對應的 PHP 函數(shù)的快捷方式:

@isset($records)
    // $records 已經(jīng)定義但不為空
@endisset

@empty($records)
    // $records 為空……
@endempty
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號