Several methods for laravel to pass variables to a view
Public function test1 () {$ first = 'xiaoqiang '; $ last = 'gongmiao'; return view ('test. welcome ')-> with ('first', $ first);/* in view of the strange phenomenon of the laravel variable, run the code in the view, put it here {$ first} * // return view ('test. welcome ')-> with ('last', $ last); // different values cannot be returned twice} public function test2 () {// $ first = 'xiaoqiang '; $ name = []; $ name ['A'] = 'xiaoqiang '; $ name [' B '] = 'xiaoqiang'; return view ('test. welcome ', $ name);/* {$ a }}{{ $ B} $ a $ B can be placed separately or together, however, you must note that $ name cannot directly use */} public function test3 () {$ name = []; $ name ['A'] = 'xiaoqiang '; $ name ['B'] = 'xiaoqiang '; return view ('test. welcome ')-> with ('name', $ name ); /* {$ name ['A'] }}{{ $ name ['B'] }}$ name ['A'] $ name ['B'] can be separated can also be placed together, however, you must note that $ name and $ name [] cannot directly use */} public function test4 () {$ first = 'xiaoqiang '; $ last = 'gongmiao '; return view ('test. welcome ', compact ('last', 'first'); //-> with ('name', $ name) // name is the variable name in your view. $ name is the variable set by yourself .}