4 回答

TA貢獻1790條經驗 獲得超9個贊
首先您需要了解何時需要使用大括號。
當您在 Blade 文件中顯示數據時,您需要使用大括號。喜歡
Hello, {{ $name }}.
您可以使用@if、@elseif、@else 和@endif 指令構造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
您的解決方案
@if(count($users) <= 5) <!-- if total number of rows in users table is less than or equal to 5 -->
<h3> total number of rows less than or equal to 5 </h3>
@endif
有關詳細信息,請參閱 laravel 文檔https://laravel.com/docs/7.x/blade#if-statements

TA貢獻1775條經驗 獲得超8個贊
您需要刪除 if 條件內的 {{ }}。
像這樣。
@if(count($users) <= 5) <!-- if total number of rows in users table is less than or equal to 5 -->
<h3> total number of rows less than or equal to 5 </h3>
@endif

TA貢獻2016條經驗 獲得超9個贊
在控制器中更改您的代碼,如下所示 -
$users = User::all();
return view('front', compact('users'));
刀片文件代碼-
@if(count($users) <= 5) <!-- if total number of rows in users table is less than or equal to 5 --><h3> total number of rows less than or equal to 5 </h3>@endif
- 4 回答
- 0 關注
- 263 瀏覽
添加回答
舉報