search

Home  >  Q&A  >  body text

How does laravel get an array?

路由器写法:

Route::get('/', function () {


   $db=[
     'id'=>1,
     'name'=>'ok'

   ];

    return view('welcome',$db);
});


weclome template:

    @foreach($db as $v)           
             {{ $v->id }}
          @endforeach

Error report:

ErrorException in 09a920b7dfeb8f66040a471f4982c97d line 42: Undefined variable: db (View: K:\demo\resources\views\welcome.blade.php)

why is that?

给我你的怀抱给我你的怀抱2754 days ago523

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 16:57:14

    return view('welcome',['db' => $db]);

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-16 16:57:14

    @foreach ($welcome as $v)
        {{ $v->id }}
    @endforeach

    reply
    0
  • Cancelreply