Vishaal
155
2
Laravel

Foreach give error when i'm trying to display it

Posted 3 months ago by Vishaal

Hello,

I'm trying to foreach some property, when i'm trying in blade it give me error message:

Controller:


$vaardigheid = DB::table('instellingens')->where([
                        ['level', '=', 'Vaardigheid'],
                    ])->select('naam')->get();

        $vaardigheid = $vaardigheid->first();

return view('vaardigheid', compact('vaardigheid'));

Blade


 @foreach($vaardigheid as $vaardigheid)
                                    <option>{{$vaardigheid->naam}}</option>
                                @endforeach
                                           

when i return the value on controller it give me output:

[{"naam":"dummy1"},{"naam":"dummy2"},{"naam":"dummy3"}]

error on blade:

ErrorException (E_ERROR) Trying to get property 'naam' of non-object (View: C:\xampp\htdocs\test\resources\views\aanvrager\vaardigheid.blade.php) Previous exceptions Trying to get property 'naam' of non-object (0)

why i'm getting this error message? i have use the foreach on other controller there is the same and there its working fine.

Please sign in or create an account to participate in this conversation.