Skip to main content

Introduction

Returning entire HTML documents as strings directly from routes and controllers is impractical. Views allow you to place all of your HTML in separate files. Views separate your controller / application logic from your presentation logic and are stored in the resources/views directory. In Laravel, views are typically written using the Blade templating language.
This view is stored at resources/views/greeting.blade.php and can be returned using the global view helper.

Creating views

To create a view, place a file with the .blade.php extension in the resources/views directory, or use an Artisan command.
The .blade.php extension tells the framework that the file contains a Blade template.

Returning views

Once a view is created, you can return it from a route or controller using the global view helper.
You can also return it using the View facade:
The first argument to the view helper corresponds to the name of the view file in the resources/views directory. The second argument is an array of data that should be made available to the view.

Nested view directories

Views may be nested within subdirectories of resources/views. “Dot” notation is used to reference nested views. For example, if your view is stored at resources/views/admin/profile.blade.php, you can return it like so:
View directory names should not contain the . character.

Returning the first available view

Using the first method of the View facade, you can return the first view that exists from a given array of views.

Checking if a view exists

To check if a view exists, use the exists method on the View facade.

Passing data to views

As you saw in the previous examples, you can pass an array of data to views and use that data within the view.
When passing data in this way, it must be an array of key/value pairs. Inside the view, you can access each value using its key. You can also add data individually using the with method. The with method returns an instance of the view object, so you can chain method calls.

Sharing data with all views

If you want to share data with every view, use the share method on the View facade. You typically place this in the boot method of a service provider.

Optimizing views

By default, Blade template views are compiled on demand. Because view compilation runs during the request, this may have a slight performance impact. The view:cache Artisan command lets you pre-compile all of the views used by your application. It’s recommended to run it as part of your deployment process.
To clear the view cache, use the following command:

Next steps

Blade templates

Learn how to use Blade syntax to build dynamic views.
Last modified on July 13, 2026