I wan to get data for two variables in same method but its not happening
function display(){
$datas=Req::all();
$products = Product::all();
return view ('products.dispaly')->with('products', $products,'datas',$datas);
}
here i want to get data from table and assign them to two separate variables $datas, and $ products? what is the correct way to do it?
4
Answers
You have to use
view
this way:Another way that is exactly the same, just less verbose, is to use
compact
:You have view name "dispaly"… I guess it should be: "display".
Try this:
or
If you have data in variables and want that data on the next page with the same name as the variables I prefer to use "compact" it is a php function that creates an array from variables and their values.
This is the same like:
But compact do it for you 🙂
To have an easy code to understand use compact is the best way