Home >Backend Development >PHP Tutorial >Laravel 5 framework learning - transferring data to views (advanced), laravel framework_PHP tutorial
We can not only transmit a data to the view, we can also transmit Array
Copy code The code is as follows:
Public function about()
{
return view('pages.about')->with([
'first' => 'Zhang',
'last' => 'Jinglin'
]);
}
A concise way is this:
Copy code The code is as follows:
Public function about()
{
$data = [];
$data['first'] = 'Zhang';
$data['last'] = 'Jinglin';
return view('pages.about', $data);
}
The result is the same, simpler is this:
Copy code The code is as follows:
Public function about()
{
$first = 'Zhang';
$last = 'Jinglin';
return view('pages.about', compact('first', 'last'));
}
compact turns the parameters into arrays, and extract does the opposite. You can check the php manual to learn about compact, and take a look at extract.