title: ErrorException Undefined Variable Laravel
body: <p>Hey guys I just started learning how to use Laravel and when I tried running the code below I get:</p>
  
  <blockquote>
    <p>Undefined variable error</p>
  </blockquote>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;ul&gt;
          @foreach ($tasks as $task)
              &lt;li&gt;{{ $task-&gt;Todo }}&lt;/li&gt;
          @endforeach
      &lt;/ul&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>this is the code used in the <code>web.php</code> file:</p>
  
  <p><strong>web.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>Route::get('/tasks', function () {
          $tasks = DB::table('tasks')-&gt;get();
      //return $tasks;
          return view('welcome',compact($tasks));
      });
  </code></pre>
  
  <p>I discovered that if I use the <code>$GLOBALS['variable'];</code> to replace the <code>$tasks</code> variable in both files it works.</p>
  
  <p>But in the example video from laracasts they didn't make use of the <code>$GLOBALS['variable'];</code></p>
  
  <p>This is the error I get:</p>
  
  <blockquote>
    <p>"Undefined variable: tasks (View: C:\Users\Friday\Documents\Documentations\laraprojects\BrainGear\resources\views\welcome.blade.php)"</p>
  </blockquote>