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 stack channel?

533


What is composer tool?

531


How can I install laravel in windows?

492


Does wordpress use laravel?

523


Explain php artisan?

516


How do I register an artisan command?

507


What is auth? How is it used?

503


How many types of middleware are there in laravel?

511


What are the steps Redirecting to Named Routes in Laravel ?

1021


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

513


What is csrf protection in laravel?

577


Tell me how to get current environment in laravel 5?

515


What is map function in laravel?

543


How do I disable csrf protection in laravel?

523


Explain events in laravel?

530