Laravel 5 framework-transfer data to views (Advanced article); laravel framework
We can not only transmit a data record to a view, but also an Array
Copy codeThe Code is as follows:
Public function about ()
{
Return view ('pages. about')-> ([
'First' => 'zhang ',
'Last' => 'jinglin'
]);
}
<H1> About {$ first }{{ $ last }}
A simple method is as follows:
Copy codeThe Code is as follows:
Public function about ()
{
$ Data = [];
$ Data ['first'] = 'zhang ';
$ Data ['last'] = 'jinglin ';
Return view ('pages. about', $ data );
}
The results are the same, which is simpler:
Copy codeThe Code is as follows:
Public function about ()
{
$ First = 'zhang ';
$ Last = 'jinglin ';
Return view ('pages. about', compact ('first ', 'last '));
}
Compact converts parameters into arrays, and extract is the opposite. You can refer to the php manual to learn about compact and learn about extract by the way.