public function index()
{
$store = Store::all(); // got this from database model
return view('store')->with('store', $store);
}
You've three options in general.
return view('store')->with('store', $store);
return view('store')->withStore($store);
return view('store')->with(compact('store'));
1.Creates a variable named store
which will be available in your view
and stores the value in the variable $store
in it.
2.Shorthand for the above one.
3.Also a short hand and it creates the same variable name as of the value passing one.
Now in your view
you can access this variable using
{{ $store->name }}
it will be same for all 3 methods.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…