Today, We want to share with you Laravel Passing Multiple Variables from Controller to View.In this post we will show you Passing multiple arrays to a view, hear for Passing Variables from the Controller to View we will give you demo and example for implement.In this post, we will learn about php – Laravel – Pass more than one variable to view with an example.
Laravel Passing Multiple Variables from Controller to View
There are the Following The simple About Laravel Passing Multiple Variables from Controller to View Full Information With Example and source code.
As I will cover this Post with live Working example to develop Passing Multiple Variables Into A Laravel 5 View, so the Passing Multiple Variables Into A Laravel 5 View for this example is following below.
- Laravel – Pass more than one variable to view
- php – Laravel – Pass more than one variable to view
- Passing multiple variables to a Laravel view
- PASSING VARIABLES FROM THE CONTROLLER TO VIEW
Example 1 : Laravel – Pass more than one variable to view
$data = [ 'member_name' => 'Jaydeep', 'member_age' => 26, 'member_email' => '[email protected]' ]; return View::make('member')->with($data);
Example 2 : php – Laravel – Pass more than one variable to view
We can Using compact()
public function show($id) { $members = DB::table('members')->join('teams', 'members.team_id', '=', 'teams.id') ->join('categories', 'members.category_id', '=', 'categories.id') ->join('subcategories', 'members.sub_category_id', '=', 'subcategories.id') ->join('statuses', 'members.status_id', '=', 'statuses.id') ->select('members.*', 'teams.name AS pname', 'categories.name AS cname', 'subcategories.name as subname', 'statuses.name as sname', 'statuses.color as scolor', 'teams.color as pcolor') ->where("members.id", "=", $id) ->orderBy('members.id', 'desc') ->get(); $statuses = DB::table('statuses')->get(); $team = DB::table('teams')->get(); $comments = DB::table('comments') ->join('users', 'comments.user_id', '=', 'users.id') >select('comments.*', 'users.name AS uname') ->where("comments.member_id", "=", $id)->get(); return view('members.show',compact('members','id', 'comments', 'statuses', 'team')); }
Example 3 : Passing multiple variables to a Laravel view
Laravel view using compact, view using with, view using Associative Methods
//Passing variable to view using compact method $members=memberinfo; $teams=teamInfo; $points=pointslist; return view('members', compact('members','teams','points')); //Passing variable to view using with Method return view('members')->with(['members'=>memberinfo,'teams'=>teamInfo,'points'=>'pointslist']); //Passing variable to view using Associative Array return view('members', ['members'=>memberinfo,'teams'=>teamInfo,'points'=>pointslist]);
We can Using Passing Data to Views in Laravel
Example 4 : PASSING VARIABLES FROM THE CONTROLLER TO VIEW
In this Example Passing multiple arrays to a view app/Http/Controllers/WelcomeController.php Into resources/views/welcome.blade.php so some changes in this Controller files.
Passing Variables from the Controller to View
//In controller public function index() { return view('welcome')->with('membername', 'Jaydeep Gondaliya'); } // Access In Blade view File {{ $membername }}
magic method to identify
//In controller public function index() { $membername = 'Jaydeep Gondaliya'; return view('welcome')->withName($membername); } // Access In Blade view File {{ $membername }}
with method to pass multiple variables
//In controller public function index() { $data = array('membername' => 'Jaydeep Patel', 'date' => date('Y-m-d')); return view('welcome')->with($data); } // Access In Blade view File You last visited {{ $membername }} on {{ $date }}.
multiple with methods
//In controller return view('welcome') ->with('name', 'Jaydeep Gondaliya') ->with('date', date('Y-m-d')); // Access In Blade view File You last visited {{ $membername }} on {{ $date }}.
using compact()
//In controller $membername = 'Jaydeep Gondaliya'; $date = date('Y-m-d'); return view('welcome', compact('membername', 'date')); // Access In Blade view File You last visited {{ $membername }} on {{ $date }}.
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Laravel Passing Multiple Variables from Controller to View.
I would like to have feedback on my Pakainfo.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.