Twittler
1 year ago
61
11
Laravel

Laravel Undefined variable:

Posted 1 year ago by Twittler

Hi guys, just got a nooby problem, i cant fetch data from db, but the strange thing is in other folder i used

Controller:

    $hosting = hosting::all() -> toArray();
    return view("index",compact("hosting"));

View:

@foreach($hosting as $host) {{$host['pavadinimas']}} @endforeach

And that worked, right now i want to make a list and i using

Controller:

    $posting = posting::all() -> toArray();
    return view("lists.list",compact("posting"));

View:

@foreach($posting as $post)

<p>{{$post['vardas']}}</p>
@endforeach 

and it;s giving me error " Undefined variable: posting (View: C:\xampp\htdocs\praktika1\resources\views\lists\list.blade.php)"

and i don't understand what i have done wrong?

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