Home >Backend Development >PHP Tutorial >Laravel 5 Basics (3) - Passing data to the view (continued)
<code> public function about() { return view('pages.about')->with([ 'first' => 'Zhang', 'last' => 'Jinglin' ]); }</code>
<code><h1>About {{ $first }} {{ $last }}</h1></code>
A concise way is this:
<code> public function about() { $data = []; $data['first'] = 'Zhang'; $data['last'] = 'Jinglin'; return view('pages.about', $data); }</code>
The result is the same, simpler is this:
<code> public function about() { $first = 'Zhang'; $last = 'Jinglin'; return view('pages.about', compact('first', 'last')); }</code>
compact turns parameters into arrays, extract does the opposite. You can check the php manual to learn about compact and learn about extract by the way.
The above introduces the basics of Laravel 5 (3) - transmitting data to the view (continued), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.