lundi 13 juin 2022

Laravel Undefined variable $

I'm getting this error:

Undefined variable $nilais

This is the code from my main.blade.php

<tbody>
            @foreach ($nilais as $nilai)
            <tr>
                <td class="text-center" scope="row"></td>
                <td></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center"></td>
                <td class="text-center">Lulus</td>
                <td class="text-center">
                    <button type="button" class="btn btn-warning"> Edit </button>
                    <button type="button" class="btn btn-danger"> Hapus </button>
                </td>
            </tr>
            @endforeach

my Controller

class MainController extends Controller
{
    public function index(){
        $nilais = Nilai::get();
        return view('main', compact('nilais'));
    }}

and this is the route

Route::get('/main', function () {
    return view('main');
});

I don't know what is wrong, please help.

I'm aware there are other questions like this, but I already tried the solutions, and nothings work.

Thank you so much.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire