Pergunta

O.k. I just set up Laravel and I'm missing a basic concept.

Route

Route::get('controllertest', 'ControllerTest@getIndex');

Controller

public function getIndex()
{
    return View::make('test_controller');
}

View

<title>{{ $title }}</title>

I've tried everything and I can't get a variable to pass from the controller to the view.

Everything works but my title is still {{ $title }}

Yes, this is basic stuff, but how do you do it?

Foi útil?

Solução

You can pass variables to your views in the following way:

public function getIndex() {
    return View::make('test_controller', [
        'title' => 'Title Value'
    ]);
}

An alternative is to use the following syntax:

public function getIndex() {
    return View::make('test_controller')->with('title', 'Title Value');
}

Check their documentation for more detail.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top