Laravel Views are stored in project_name/resources/views directory. Generally, the view contains the HTML which will be served by the application.
The following example to understand more about Views −
Since this view is stored at resources/views/world.blade.php, we may return it using the global view helper like so:
For example, if your view is stored at resources/views/admin/category.blade.php, you may reference it like so:
You may pass an array of data to views:
Inside the view, Access each value using its corresponding key, like the
<?php echo $singlekey; ?>
The following example to understand more about Views −
Step 1 − Copy the bellow code and save it to resources/views/world.php
<html>
<body>
<h1>Hi, {{ $name }}</h1>
</body>
</html>
Since this view is stored at resources/views/world.blade.php, we may return it using the global view helper like so:
Route::get('/', function () {
return view('world', ['name' => 'Nakiya']);
});
Views may also be nested within sub-directories of the resources/views directory.For example, if your view is stored at resources/views/admin/category.blade.php, you may reference it like so:
return view('admin.category', $data);
Passing Data To Views
You may pass an array of data to views:
return view('world', ['name' => 'Nakiya']);
When passing information in this method, the data should be an array with key, value pairs.Inside the view, Access each value using its corresponding key, like the
<?php echo $singlekey; ?>
No comments:
Post a Comment