title: How to get last 12 months user login data by per month in laravel
body: <p>I am trying to get user login activity per month and then to show it in statistic in a bar chat. But the problem i am facing is that its not giving me any data. I will share my code first it will easier to explain my problem</p>
  
  <p>My LoginActivity Model</p>
  
  <pre><code>class LogActivity extends Model
  {
      protected $table = 'laravel_logger_activity';
  
      public function logActivity(){
          $videoPerMonth = array();
  
          for ($i=1; $i&lt;=12; $i++){
              $age= 12 - $i;
              $userPerMonth[$i] = count(LogActivity::whereNotIn('userId', [1])-&gt;whereMonth('created_at', '=', date('n') -$age)-&gt;get());
  
          }
       }
      }
  </code></pre>
  
  <p>In this i do get user's activity per month but this is not accurate because being the first month if u subtract 12 value goes to negative. And i dont get actual reults.
  So, after reading few articles i changed my code to this</p>
  
  <pre><code>$userPerMonth =count( LogActivity::whereNotIn('userId', [1])-&gt;whereMonth('created_at', '&gt;=', Carbon::now()-&gt;subMonth(12))-&gt;get());
  return json_encode($userPerMonth);
  </code></pre>
  
  <p>But this returns empty.What shall i do ?</p>
  
  <p>I want to get data by month vs activity 
  For example nov 2017 : 300 , dec 2017:800,jan 01 2018:100 
  Something like that so i can put in bar chat 
  Can anyone please help me with this
  Thanks</p>