2

I´m define my method controller index() and I pass param title for show in my html view:

class WebController extends BaseController{
    public $layout = 'layout.base';

    /*Index*/
    public function index(){
        $this->layout->title = 'Index Title';
        return View::make('pages.index');
    }
}

But when I load the page return this error: enter image description here

And in my 'app\views\layout\base.blade.php' i have:

<!DOCTYPE html>
<html lang="es">
    <head>
        <title>{{$title}}</title>
        @section('metas')
        @show

        @section('styles')
        @show
    </head>

This is my route.php:

Route::get('/index',['as' => 'pages.index', 'uses' => 'WebController@index']);

How to fix this? Thank you very much!

Funny Frontend
  • 3,807
  • 11
  • 37
  • 56

3 Answers3

2

Try something like this, you have to pass the variable when you return the View::make(..). When you would like to pass more variables you can use the compact(); function.

/*Index*/
    public function index(){
        $title = 'Index Title';
        return View::make('pages.index', $title);
    }

Example with compact();

return View::make('pages.index', compact('title','description'));
Duikboot
  • 1,093
  • 1
  • 12
  • 24
2

Try to add an array with data to the view::make:

return View::make('pages.index', array('title' => 'Title'));
Nilesh
  • 20,521
  • 16
  • 92
  • 148
Sander
  • 56
  • 4
2

try to write call your view from

return View::make('pages.index'); 

to

return View::make('pages.index')->with('title', $this->layout->title);
Sachin Shukla
  • 1,249
  • 14
  • 17