title: Passing counter variable from controller to View in laravel 5
body: <p>I am trying to make a counter in my laravel site. This counter takes all the comments from model <em>Comments</em> which were created from Carbon::now() until startofMonth(). So I have my controller and function counter as so:</p>
  
  <pre><code> class CommentsController extends Controller
  {
          public function counter()
      {
          $new_comments=Comments::where('created_at', Carbon::now()-&gt;startofMonth())-&gt;get();
  
          $counted-&gt;count($new_comments['created_at']);
  
  
          return View::make('pages.dashboard')-&gt;with('new_comments', $counted);        
      }
  }
  </code></pre>
  
  <p>My blade template:</p>
  
  <pre><code>&lt;div class="row"&gt;
         &lt;div class="col-xs-3"&gt;
               &lt;i class="fa fa-comments fa-5x"&gt;&lt;/i&gt;
         &lt;/div&gt;
             &lt;div class="col-xs-9 text-right"&gt;
                &lt;div class="huge"&gt;{{!!$new_comments!!}}&lt;/div&gt;
                &lt;div&gt;New Comments!&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I keep getting a variable undefined error message even though the variable is called in the controller! The dashboard page works fine when the variable is not called in the blade template.</p>
  
  <p>EDIT:</p>
  
  <p>I have managed to get this working if ignore the controller and add the following into my view:</p>
  
  <pre><code>{{App\Comments::count()}}
  </code></pre>
  
  <p>This only shows the total amount of rows in the table Comments, but I will try and add the mySQL query in to it.</p>
  
  <p>I still don't know why it can't be called as a variable from the controller.</p>