Arturs Undzenko
Arturs Undzenko

Reputation: 1

View::make doesn't return a data from controller to view

public function getList()
{
    $posts=\Posts::allPosts();
    $this->layout->content=\View::make('admin.posts.list', $posts);
}

So I'm sending the $posts array to my view, but I get an error when I try to var_dump(...) it that it doesn't exist.

Upvotes: 0

Views: 229

Answers (3)

kok
kok

Reputation: 226

The easiest thing to do here could be to use compact()

public function getList()
{
    $posts = \Posts::allPosts();

    $this->layout->content = \View::make('admin.posts.list', compact('posts'));
}

It does basically the same as array('posts' => $posts)

Upvotes: 0

Yada
Yada

Reputation: 31225

A common idiom to use an $data array.

public function getList()
{
    $data = array(
        'posts' => Posts::allPosts(),
        'morestuff' => $variable,
    );

    $this->layout->content=\View::make('admin.posts.list')->with($data);
}

Upvotes: 1

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87749

You should inform the variable name to Blade:

public function getList()
{
    $posts=\Posts::allPosts();
    $this->layout->content=\View::make('admin.posts.list', array('posts' => $posts));
}

Upvotes: 1

Related Questions