Hey guys i just started learning how to use laravel and when i tried running the code below i get an Undefined variable error
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
@foreach ($tasks as $task)
<li></li>
@endforeach
</ul>
</body>
</html>
this is the code used in the web.php file
Route::get('/tasks', function () {
$tasks = DB::table('tasks')->get();
//return $tasks;
return view('welcome',compact($tasks));
});
I discovered that if i use the $GLOBALS['variable']; to replace the $tasks variable in both files it works. But in the example video from laracasts they didn't make use of the $GLOBALS['variable']; This is the error i get
"Undefined variable: tasks (View: C:\Users\Friday\Documents\Documentations\laraprojects\BrainGear\resources\views\welcome.blade.php)"
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2FeQcyn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire