Views are stored in resources/views directory. Generally, the view contains the HTML which will be served by the application.
Test the URL:-
http://localhost:8000/testPass an array to view helper function. After passing an array, we can use the key to get the value of that key in the HTML file.
The value of the key name will be passed to test.php file and $name will be replaced by that value.
There is a method called share() which can be used for this purpose. The share() method will take two arguments, key and value. Typically share() method can be called from boot method of service provider. We can use any service provider, AppServiceProvider or our own service provider.
Create two view files — test.php and test2.php with the same code. These are the two files which will share data. Copy the following code in both the files. resources/views/test.php & resources/views/test2.php
<html>
<body>
<h1><?php echo $name; ?></h1>
</body>
</html>
Step 3 − Change the code of boot method in the file app/Providers/AppServiceProvider.php as shown below. (Here, we have used share method and the data that we have passed will be shared with all the views.) app/Providers/AppServiceProvider.php
public function boot() {
view()->share('name', 'itechxpert');
}
Trending Tutorials