Can't pass data from controller to blade template laravel
13,106
Solution 1
There are many ways to achieve this, as @Gravy pointed out, but judging by the way she is trying to write the code, the solution would be:
$data = array();
$this->layout->with('data', $data);
$this->layout->content = View::make('home');
See more here: http://forums.laravel.io/viewtopic.php?pid=58548#p58548
Solution 2
$data =
[
'page_title' => 'Login',
'second_item' => 'value'
...
];
return View::make('authentication/login', $data);
// or
return View::make('authentication/login', compact('data'));
// or
return View::make('authentication/login')->with($data);
// or
return View::make('authentication/login')->with(['page_title' => 'Login', 'second_item' => 'value']);
// or
return View::make('authentication/login')->with(array('page_title' => 'Login', 'second_item' => 'value'));
Solution 3
$data = array('page_title'=>'Login','second_item'=>'value');
return View::make('authentication/login', $data);
Related videos on Youtube
Author by
Claire
Updated on September 15, 2022Comments
-
Claire over 1 year
In my page controller I have
$this->layout->content = View::make('authentication/login')->with('page_title','title');
I am using a blade file for my template. In the head of the html, I have
<title>{{$page_title}}</title>
I get an error that
$page_title
is undefined.What I want ideally is a
$data=array('page_title'=>'Login','second_item'=>'value')...
. But as I cannot get the basic passing of a variable to a view working, I am sticking with that first of all. -
Claire over 10 yearsI get the
$content
variable echoing fine. It's the $page_title that doesn't echo. Also, why dot notation and not '/' between folders?