How to Passing Data to Views ?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a Terminable Middleware ?

555


How to set database connection in laravel?

421


Tell me in which language it was written?

406


How do I set up the eloquent relationships between the aforementioned comments and authors, including creating the schema design?

388


What is redirect routes?

415






Is laravel an mvc framework?

419


How do I require authentication for a set of routes associated with a subdomain?

418


What are accessors and mutators in eloquent and why should you use them?

409


What is method spoofing?

406


Explain how to generate pretty urls in laravel?

431


Explain short notes on Laravel - Artisan Console and commands ?

1009


How to Sharing Data with all Views ?

1021


How to rollback last migration?

447


List out common artisan commands used in laravel.

377


Is laravel safe from sql injection?

391