亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取 laravel 中跨度值的計數

獲取 laravel 中跨度值的計數

PHP
慕沐林林 2022-01-14 18:11:23
我從數據庫中檢索數據,就像在控制器中一樣:$users = DB::select("select users.id, users.name, users.email, count(is_read) as unread         from users LEFT  JOIN  messagesnews ON users.id = messagesnews.from and is_read = 0 and messagesnews.to = " . Auth::id() . "       where users.id != " . Auth::id() . "         group by users.id, users.name, users.email");return view('admin.home.index', compact('users'));鑒于:@foreach($users as $user)                                      @if($user->unread)      <span class="pending">{{ $user->unread }}</span>    @endif@endforeach干得好 我怎樣才能得到一個數字來計算它們6
查看完整描述

2 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

試試這個,


 @php $totlUnread = 0; @endphp

 @foreach($users as $user)                                  

    @if($user->unread)

        @php $totlUnread+=$user->unread; @endphp

     @endif

@endforeach

@php echo "<span class='pending'>$totlUnread</span>"; @endphp


查看完整回答
反對 回復 2022-01-14
?
德瑪西亞99

TA貢獻1770條經驗 獲得超3個贊

        var sum = 0;

            $(".pending").each(function() {

                sum += parseInt($(this).html());

            });

            return sum;

或者


   <?php 

    $all_unread = array_column($users, 'unread');

    array_sum($all_unread);

  ?>


查看完整回答
反對 回復 2022-01-14
  • 2 回答
  • 0 關注
  • 150 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號