Pass Data to Views

#As an array

return view('greetings', ['name' => 'Victoria']);

#Using with()

return view('greeting')
            ->with('name', 'Victoria')
            ->with('occupation', 'Astronaut');

Access each value using the data's keys

<html>
    <body>
        <h1>Hello, {{ $name }}</h1>
        <!-- Or -->
        <h1>Hello, <?php echo $name; ?></h1>
    </body>
</html>
Comments