Views

Blade views are returned using the view() helper

Route::get('/', function () {
    return view('welcome', ['name' => 'Samantha']);
});

See: Views

Subdirectories

// resources/views/admin.profile.blade.php
return view('admin.profile');

view helper

Return a view from a route with the view() helper

Route::get('/', function () {
    return view('greeting', ['name' => 'James']);
});

See: View Routes and Helpers

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>

Intro

<!-- View stored in resources/views/greeting.blade.php -->
<html>
    <body>
        <h1>Hello, <?php echo $name; ?></h1>
    </body>
</html>

Create a view by placing a file with the .blade.php extension in the resources/views directory.

Comments