Views
Introduction
While it's not practical to return entire HTML document strings directly from your routes and controllers, views offer a convenient way to organize HTML in separate files.
Views help in separating your controller/application logic from your presentation logic and are stored in the resources/view directory. In Dreamfork, view templates are commonly written using the simple Vision template engine. A simple view might look something like this:
<!-- View stored in resources/views/greeting.vision.php -->
<html>
<body>
<h1>Welcome, {{ $name }}</h1>
</body>
</html>
Given this view is stored at resources/views/greeting.vision.php, you can return it using the global view helper like this:
Route::get('/', function() {
return view('greeting', ['name' => 'John']);
});
Passing Data To Views
As demonstrated in the previous example, you can pass an array of data to views to make that data available within the view:
return view('greeting', ['name' => 'John']);
When passing information in this manner, the data should be an array with key/value pairs. After providing data to a view, you can access each value within your view using the data's keys, for example, <?php echo $name; ?>.