2017-01-01 8 views
0

User.phpLaravelスコープ照会とカウントして表示

public function queryCountusers($query){ 
      $query->where(['confirmation' => true])->whereIn('role_id', [2, 3])->count(); 
     } 

UserController.php

public function index() { 
//  $users = App\User::popular()->active()->orderBy('created_at')->get(); 
     $count_user = User::countusers(); 
     return view('admin.index', compact('count_user')); 
    } 

main.blade.php

<div class="tile-stats tile-red"> 
       <div class="icon"><i class="entypo-users"></i></div> 
       <div class="num" data-start="0" data-end="{{$count_user}}" data-postfix="" data-duration="1500" data-delay="0">0</div> 
       <h3>Registered users</h3> 
       <p>so far in our blog, and our website.</p> 
      </div> 

問題は、私がいるさ

未定義のメソッドへ

コール を照らし\データベース\クエリー\ビルダー:: countusers()

これで私を助けてください。 THakns

答えて

0

あなたがscopesを使用しようとしている場合は、

変更

public function queryCountusers($query){ 
     $query->where(['confirmation' => true])->whereIn('role_id', [2, 3])->count(); 
    } 

public function scopeCountusers($query){ 
     return $query->where(['confirmation' => true])->whereIn('role_id', [2, 3])->count(); 
    } 
+0

にまだエラーがまだそこに – d3cypher

+0

同じエラーメッセージのですか? – shoieb0101

+0

はい、あなたはまだエラーがあります。 – d3cypher

関連する問題