I have been having a problem with this for hours now, and I don't know what is wrong. I am trying to make a list of registered users in Laravel but it keeps giving me the error:
"Undefined variable: users (View: C:\xampp\htdocs\laraveltest1\links\resources\views\home.blade.php)"
I have asked around on the Laravel Discord server. We've tried several things with no luck such as changing names and changing up the code.
Home.blade.php
@foreach ($users as $user) {
<tbody>
<tr>
<td>{{ $user->name }}</td>
</tr>
</tbody>
@endforeach
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
class UserController extends Controller
{
public function index()
{
$users = DB::table('users')->get();
return view()-> with ('home', ['users' => $users]);
}
}
I want to have a list, but it gives me an error code stated above.