控制器没有正确传递变量 - Laravel

时间:2014-01-21 11:35:22

标签: php laravel

有人可以告诉我为什么会收到此错误:

“未定义的变量:列表(查看:\ app \ views \ pages \ listings.blade.php)”

控制器

class ListingsController extends BaseController {

    public function showListings() {
        $listings = Listing::paginate(10);
        return View::make('pages.listings', $listings);
    }

}

查看

    <div class="container">

        <div id="main">
            <div class="row">
                <div class="span9">
                    <h1 class="page-header">Listings</h1>
                        @foreach($listings as $listing)
                            {{ $listing->address }}
                        @endforeach
                </div>
            </div>
        </div>
    </div>
    @include('includes.footer')

1 个答案:

答案 0 :(得分:4)

尝试这样做:

return View::make('pages.listings')->with('listings', $listings);

return View::make('pages.listings', array('listings' => $listings));

甚至

return View::make('pages.listings', compact('listings'));