title: Retrieve from database, calculate and post to the view
body: <p>I would like to calculate the difference between two dates and post the result to the view.  The table contains the following rows:</p>
  
  <blockquote>
    <p>Id, AuthorId, duedate,body</p>
  </blockquote>
  
  <p>I know how to calculate the difference between two dates, but this is for a single row.  Now, I'm pulling multiple rows from the database, and according to laravel I'm not supposed to perform any calculation in the view.</p>
  
  <p>Below is from the controller:</p>
  
  <pre><code> public function index()
  {
      //
  
      $posts = Post::all();
      $to = \Carbon\Carbon::now();
      $from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', '2015-5-6 9:30:34');
  
      $diff_in_days = $to-&gt;diffInDays($from);
  
      return view('blog.index',['posts'=&gt;$posts,'diffdays'=&gt;$diff_in_days]);
  }
  </code></pre>
  
  <p>I just used a dummy date for the <code>$from</code> variable.  It's supposed to be replaced with the due datedate value from the database.  I am not sure how to approach so I can perform the calculation in the controller before passing it to the view.<br>
  I'm still learning laravel, any help will be great.</p>