Today, We want to share with you laravel pass data to view from controller.In this post we will show you sharing data with all views laravel, hear for how to pass array from controller to view in laravel? we will give you demo and example for implement.In this post, we will learn about Laravel Passing Multiple Variables From Controller To View with an example.
how to pass data from one view to another view in laravel?
There are various ways of passing data to views:
- By using the name array
- By using with() function
- By using compact() function
using Name array
member.blade.php
Name of the Members are :
"; echo $name2; echo "
"; echo $name3; ?>
MemberController.php.
'Sejal','name2'=>'Pankila','name3'=>'Diopti']); } }
web.php
Route::get('/profiles', 'MemberController@display');
using with() function
member.blade.php
Member id is :
MemberController.php
with('id',$id); } }
using Route
Route::get('/profiles/{id}', 'MemberController@display');
using compact() function
member.blade.php
Name is :
MemberController.php
web.php file.
Route::get('/profiles/{name}', 'MemberController@display');Full Example
Member.blade.php
Members Details :
"; echo "Member name is :" .$name; echo "
"; echo "Member password is :" .$password; ?>MemberController.php
web.php
Route::get('/profiles/{id}/{name}/{password}', 'MemberController@display');I hope you get an idea about laravel return view with json data.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.