Reputation: 71
How do I pass a multiple variable into a view and how do I get it?
supposing i have a two variable
$dateFrom = 2016-02-22
$dateTo = 2016-02-25
am i doing right with my route?
return View('admin.inventory-bloodCollectionView1')->with($dateFrom)->with($dateTo);
and how do i get it from the view?
Upvotes: 1
Views: 98
Reputation: 374
You can also pass in the form of array just like this.
return view('admin.inventory-bloodCollectionView1')
->with(array('fromDate' => $dateFrom, 'toDate'=> $dateTo));
These variables will be available in view as $fromDate and $toDate.
Upvotes: 0
Reputation: 240
Another convenient way to pass variables is using compact.
return View('admin.inventory-bloodCollectionView1', compact('dateFrom', 'dateTo'));
Upvotes: 1
Reputation: 21
You can pass multiple variables or items in to the view by supplying an array to the view method. For example :
return view('view_name', ['value_name' => value , 'value_name2' => value2 ]);
U can use the items in the view now using : $value_name and $value_name2 respectively.
Upvotes: 1
Reputation: 50787
You need to alias the name of the variable as the first, argument, like so:
return View('admin.inventory-bloodCollectionView1')
->with('dateFrom', $dateFrom)
->with('dateTo', $dateTo);
Now they are available in the view as $dateTo
and $dateFrom
.
Upvotes: 1