4 回答

TA貢獻(xiàn)1790條經(jīng)驗 獲得超9個贊
首先您需要了解何時需要使用大括號。
當(dāng)您在 Blade 文件中顯示數(shù)據(jù)時,您需要使用大括號。喜歡
Hello, {{ $name }}.
您可以使用@if、@elseif、@else 和@endif 指令構(gòu)造if 語句。這些指令的功能與其 PHP 對應(yīng)指令相同:
@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
有關(guān)詳細(xì)信息,請參閱 laravel 文檔https://laravel.com/docs/7.x/blade#if-statements

TA貢獻(xiàn)1775條經(jīng)驗 獲得超8個贊
您需要刪除 if 條件內(nèi)的 {{ }}。
像這樣。
@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貢獻(xiàn)2016條經(jīng)驗 獲得超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 關(guān)注
- 281 瀏覽
添加回答
舉報