title: LARAVEL 7, Undefined variable, cant pass Variable from Controller to View
body: <p>im new at Laravel, and im making a CRUD following this tutorial:</p>
  <p><a href="https://appdividend.com/2020/03/13/laravel-7-crud-example-laravel-7-tutorial-step-by-step/" rel="nofollow noreferrer">https://appdividend.com/2020/03/13/laravel-7-crud-example-laravel-7-tutorial-step-by-step/</a></p>
  <p>first i made it on my own, and then i just copied the code from GitHub, in both cases im getting in the variable inside the @foreach:</p>
  <p>Facade\Ignition\Exceptions\ViewException
  Undefined variable: coronacases</p>
  <p>I searched a bit and tryed some other solutions with no luck, so i started a new project with just index function to see if data is passed from controler to view.</p>
  <p>This is my code,
  Controller:</p>
  <pre><code>// TestController
  
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  class TestController extends Controller
  {
  
      public function index()
      {
          $name = 'hugo';
  
          return view('test', compact('name'));
      }
  </code></pre>
  <p>Alternative sintaxys tested in Controller:</p>
  <pre><code>/***
  * return view('/test', compact('name'));
  * return view('name', ['name' =&gt; 'James']); with out $name = 'hugo'; earier.
  * return view('test', $name]);
  * return view('test')-&gt;with('name', $data);
  * return view('test')-&gt;with('name', 'hugo'); with out $name = 'hugo'; earier.
  * other solutions tryed here dosnt seems to change anything.
  ***/
  </code></pre>
  <p>Routes:</p>
  <pre><code>Route::get('/', function () {
      return view('test');
  });
  Route::resource('test', 'TestController');
  </code></pre>
  <p>Alternative Routes Tested:</p>
  <pre><code>/***
  * Route::get('/test', 'TestController@index');
  *
  * Route::get('/', function () {
  *    return view('test', ['name' =&gt; 'James']);
  *}); //this one worked, but its not getting data from Controller, so its now what i need
  *
  *Route::get('/', function () {
  *    return view('test', ['name' =&gt; $data]);
  *}); //didnt work
  *
  ***/ // I think that the problem is here, im having trouble understanding Routes at Laravel Docs
  </code></pre>
  <p>View:</p>
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;h1&gt;Hello, {{ $name }}&lt;/h1&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Also tryed at View:</p>
  <pre><code>/***
  * $data
  * &lt;?php echo $data ?&gt;
  * {{ $name ?? '' }}
  ***/
  </code></pre>
  <p>All this Test, and im getting same error, Im missing Something and i cant figure it out... or i have some trouble with Laravel,the sure things is that im stuck.</p>
  <p>Complementary info:</p>
  <p><a href="https://i.stack.imgur.com/Tz92k.png" rel="nofollow noreferrer">php artisan route:list resoult:</a></p>
  <p>Environment information</p>
  <p>Laravel version:
  7.16.1,
  Laravel locale:
  en,
  Laravel config cached:
  false,
  PHP version:
  7.4.6.</p>
  <p>Request</p>
  <p>URL
  <a href="http://127.0.0.1:8000/" rel="nofollow noreferrer">http://127.0.0.1:8000/</a>
  Method
  GET</p>
  <p>Headers</p>
  <p>host
  127.0.0.1:8000
  user-agent
  Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0</p>
  <p>I also tryed with php artisan view:cache &amp;&amp; php artisan view:clear</p>