Home > Backend Development > PHP Tutorial > Laravel 5 Basics (3) - Passing data to the view (continued)

Laravel 5 Basics (3) - Passing data to the view (continued)

WBOY
Release: 2016-08-08 09:26:53
Original
947 people have browsed it
  • We can not only send data to the view, we can also send Array
<code>    public function about()
    {
        return view('pages.about')->with([
            'first' => 'Zhang',
            'last' => 'Jinglin'
        ]);
    }</code>
Copy after login
<code><h1>About {{ $first }} {{ $last }}</h1></code>
Copy after login

A concise way is this:

<code>    public function about()
    {
        $data = [];
        $data['first'] = 'Zhang';
        $data['last'] = 'Jinglin';
        
        return view('pages.about', $data);
    }</code>
Copy after login

The result is the same, simpler is this:

<code>    public function about()
    {
        $first = 'Zhang';
        $last = 'Jinglin';
        return view('pages.about', compact('first', 'last'));
    }</code>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template