Assign data to PHP variables
P粉256487077
P粉256487077 2023-09-05 13:12:09
0
1
489
<p>I want to use the same method to get the data of two variables, but it doesn’t happen</p> <pre class="brush:php;toolbar:false;">function display(){ $datas=Req::all(); $products = Product::all(); return view ('products.dispaly')->with('products', $products,'datas',$datas); }</pre> <p>Here I want to get the data from the table and assign them to two separate variables $datas and $products? What is the correct approach? </p>
P粉256487077
P粉256487077

reply all(1)
P粉718165540

You must use view like this:

return view(
    'products.dispaly',
    [
        'products' => $products,
        'datas' => $datas,
    ]
);

Another method that is exactly the same, just less verbose, is to use Compact:

return view('products.dispaly', compact('products', 'datas'));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template