Laravel count amount where the value of a key is true in multidemensional array
<p>I have an array that looks like this when dd'd out :)</p>
<pre><code>array:2 [▼
  0 =&gt; Comment {#253 ▼
    #guarded: []
    #table: &quot;comments&quot;
    +timestamps: false
    #connection: null
    #primaryKey: &quot;id&quot;
    #perPage: 15
    +incrementing: true
    #attributes: array:7 [▶]
    #original: array:7 [▼
      &quot;id&quot; =&gt; &quot;1&quot;
      &quot;on_projects&quot; =&gt; &quot;2&quot;
      &quot;from_user&quot; =&gt; &quot;19&quot;
      &quot;body&quot; =&gt; &quot;hi&quot;
      &quot;unread&quot; =&gt; &quot;1&quot;
      &quot;created_at&quot; =&gt; &quot;2016-06-13 23:54:39&quot;
      &quot;updated_at&quot; =&gt; &quot;0000-00-00 00:00:00&quot;
    ]
    #relations: []
    #hidden: []
    #visible: []
    #appends: []
    #fillable: []
    #dates: []
    #dateFormat: null
    #casts: []
    #touches: []
    #observables: []
    #with: []
    #morphClass: null
    +exists: true
    +wasRecentlyCreated: false
  }
  1 =&gt; Comment {#269 ▶}
]
</code></pre>
<p>Now my goal is to count the amount of where the unread key is true.</p>
<p>This is what I've tried but doesn't seem to be working.</p>
<pre><code>$unreads = $comments-&gt;where('unread', 1);
dd(count($unreads));
</code></pre>
<p>I get this error:</p>
<blockquote>
<p>Call to a member function where() on array</p>
</blockquote>
<p>Anyone can help me out here?</p>
<p>Many thanks in advance!</p>
<h2>EDIT</h2>
<pre><code>$uid = Auth::user()-&gt;id;
$projects = User::find($uid)-&gt;projects;
       
//comments
if (!empty($projects)) {
  foreach ($projects as $project) {              
     $comments_collection[] = $project-&gt;comments;
  }
}

if (!empty($comments_collection)) {
     $comments = array_collapse($comments_collection);
     $unreads = collect($comments)-&gt;where('unread', 1)-&gt;count();
     dd($unreads);
}
</code></pre>
<p>This gives me 0 it should give me 2 since I have 2 comments with unread 1</p>