Maison > Article > développement back-end > Laravel 向视图传递变量的3种方法
方法1,
//routs.phpRoute::get('/about',function(){$first = 'hello';return view('about')->with('a',$first);});
接收变量
//about.blade.php{{ $a }}
方法2,
//routs.phpRoute::get('/about',function(){$data = array('a' => 'O','b' => 'K');return view('about',$data);});
接收变量
{{ $a }}{{ $b }}
方法3,
//routs.phpRoute::get('/about',function(){$first = 'hello';$last = 'world';//参数名称要对应return view('about',compact('first','last'));});
接收变量
//about.blade.php{{ $first }}{{ $last }}