How to Passing Data to Views ?



How to Passing Data to Views ?..

Answer / rachana devi

While building application it may be required to pass data to the views.
Pass 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.

Example :

Observe the following example to understand more about passing data to views -
Copy the following code and save it at resources/views/test.php

<html>
<body>
<h1><?php echo $name; ?></h1>
</body>
</html>

Add the following line in app/Http/routes.php file to set the route for the above view.
app/Http/routes.php

Route::get('/test', function(){
return view('test',[‘name’=>’Virat Gandhi’]);
});

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Laravel PHP Framework Interview Questions

What can I do with laravel?

0 Answers  


Describe laravel service provider?

0 Answers  


What is meant by Laravel - Ajax ?

1 Answers  


What is routing and how, and what are the different ways to write it?

0 Answers  


What is laravel orm?

0 Answers  






What is monolog library?

0 Answers  


Why composer is used in laravel?

0 Answers  


What are the example of services?

0 Answers  


List the default ports that are forwarded to your homestead environment?

0 Answers  


What is method spoofing in laravel?

0 Answers  


What are class traits?

0 Answers  


How do I assign several roles to users and permit the users to perform some actions based on those roles?

0 Answers  


Categories