<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 12. Blade if/else/unless/or 這一節來講講 `blade` 這個 view engine 的一些關于判斷的指令。 ## 1. if 首先在 action 加一個變量,找到 `app/Http/PagesController.php` 文件,修改其內容如下: ``` // app/Http/PagesController.php <?php ... class PagesController extends Controller { ... public function blade() { $gender = 'femffffale'; $text = 'Hello there!'; return view('blade.bladetest', compact('gender', 'text')); } } ``` 然后我們在 view中來判斷這個 `$gender` 變量的內容。 找到 `resources/views/blade/bladetest.blade.php` 文件,修改其內容如下: ``` ... @section('body') <div class="jumbotron"> <h1 class="display-3"> Your gender is @if($gender == 'male') male @elseif($gender == 'female') female @else unknown @endif </h1> </div> <div class="row marketing"> ... </div> @endsection ``` 頁面上會這么顯示: ![](https://box.kancloud.cn/9e4b210157dcb473cf4bf752a79d6b3b_2462x1040.png) 結合上面的 `@if` 指令的判斷,因為 `$gender` 的值為 `femffffale`,即不是 `male`,也不是 `female`,所以最后顯示 `unknown`。 可以分別改成 `male` 或 `female` 來試試效果。 很容易理解。 ## 2. unless `unless` 其實 `!if`,`if` 的相反的意思。 我們來個例子說明一下。 ``` ... @section('body') <div class="jumbotron"> <h1 class="display-3"> ... </h1> <p class="lead"> @unless(empty($text)) {{ $text }} @endunless @if(!empty($text)) {{ $text }} @endif </p> </div> <div class="row marketing"> ... </div> @endsection ``` 最后顯示: ![](https://box.kancloud.cn/2773a4c75683c8ff90caefb40094393b_2356x1112.png) ## 3. isset 和 or `isset` 是判斷變量是否存在。 ``` <p>{{ isset($variableDoesNotExist) ? $variableDoesNotExist : 'The variable does not exist' }}</p> ``` 效果如下: ![](https://box.kancloud.cn/3206ae8218cba35ce7472d726afe5273_2306x1072.png) 它也可以用 `or` 來寫,結果一樣的。 ``` <p>{{ $variableDoesNotExist or 'This really does not exist' }}</p> ``` 完結。 下一篇:[Ruby 程序員學習 laravel 框架筆記 (13)-factories, faker and seeding](https://www.rails365.net/articles/ruby-cheng-xu-yuan-xue-xi-laravel-kuang-jia-bi-ji-13-factories-faker-and)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看