从View向Controller传值
<html>
<body>
<form action="{{url('/R_construct')}}" method="get">/*对应get方法,R_Controller路由*/
你的链表<br/>
<input type="text" name="list">//要传到Controller里的变量名为list
<input type="submit" value="Submit">
</form>
</body>
</html>
public function R_construct(Request $request)
{
$str = $request->input('list');//从View中接受list变量并存入$str
$list = explode(" ", $str);
$size = count($list);
for($i = 1; $i <= $size; $i++)
{
DB::table('LinkedList')
->insert(
['id' => $i, 'name' => $list[$i-1]]
);
}
return view('construct_success');//返回construct_success.blade.php页面
}
Controller向View传值
传参数
public function size()
{
$count = DB::table('LinkedList')
->count();
return view('size_success', ['size' => $count]);/*将$count的值存入size传到size_success.blade.php*/
}
<html>
<body>
<h1>链表长度为{{$size}}</h1><br>//用{{$size}}接收参数
<div class="links">
<a href={{ url('/') }}>首页</a>
</div>
</body>
</html>
传数据库值或传类
public function print_list()
{
$print = DB::table('LinkedList')->get();
return view('print_success', ['print' => $print]);
}
<html>
<body>
<h1>链表为</h1>
@forelse($print as $prints)//用forelse或foreach等方法便历
<h3>{{$prints->name}}</h3>
@empty
<h3>空</h3>
@endforelse
<div class="links">
<a href={{ url('/') }}>首页</a>
</div>
</body>
</html>