Student代码
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
public $students=[
['id'=>1,'xh'=>'202020411134','xingming'=>'毕志慧','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>2,'xh'=>'202020411015','xingming'=>'卞春云','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>3,'xh'=>'202020411131','xingming'=>'曹鲁丹','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>4,'xh'=>'202020411170','xingming'=>'陈润泽','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>5,'xh'=>'202020411001','xingming'=>'陈珊珊','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>6,'xh'=>'202020411017','xingming'=>'程新宇','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>7,'xh'=>'202020411158','xingming'=>'仇硕','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>8,'xh'=>'202020411050','xingming'=>'杜明童','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>9,'xh'=>'202020411116','xingming'=>'葛金娇','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>10,'xh'=>'202020411008','xingming'=>'郭天宇','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>11,'xh'=>'202020411004','xingming'=>'李洪超','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>12,'xh'=>'201535070031','xingming'=>'李继祥','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>13,'xh'=>'202020411147','xingming'=>'李正','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>14,'xh'=>'202020411157','xingming'=>'梁晶','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>15,'xh'=>'202020411036','xingming'=>'梁新焜','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>16,'xh'=>'202020411031','xingming'=>'刘彦均','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>17,'xh'=>'202020411196','xingming'=>'马晓春','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>18,'xh'=>'202020411142','xingming'=>'门政屹','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>19,'xh'=>'202020411098','xingming'=>'任鑫','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>20,'xh'=>'202020411023','xingming'=>'宋梓豪','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>21,'xh'=>'202020411046','xingming'=>'孙中旭','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>22,'xh'=>'202020411097','xingming'=>'王方明','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>23,'xh'=>'202020411119','xingming'=>'王光超','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>24,'xh'=>'202020411060','xingming'=>'王静雯','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>25,'xh'=>'202020411160','xingming'=>'王茂鹏','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>26,'xh'=>'202020411081','xingming'=>'吴孟然','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>27,'xh'=>'202020411055','xingming'=>'徐子棋','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>28,'xh'=>'202020411034','xingming'=>'许鑫江','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>29,'xh'=>'202020411067','xingming'=>'于楠','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>30,'xh'=>'202020411087','xingming'=>'袁昕','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>31,'xh'=>'202020411041','xingming'=>'张德朋','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>32,'xh'=>'202020411077','xingming'=>'张红叶','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>33,'xh'=>'202020411047','xingming'=>'张景俞','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>34,'xh'=>'202020411110','xingming'=>'张艳东','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>35,'xh'=>'202020411073','xingming'=>'张云琪','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'女'],
['id'=>36,'xh'=>'202020411167','xingming'=>'周冉','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>37,'xh'=>'202020411059','xingming'=>'朱振琨','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
['id'=>38,'xh'=>'202020411162','xingming'=>'卓立龙','nianji'=>'2020','zhuanye'=>'软件技术','zhuanyebianhao'=>'521','banji'=>'4','xuexixingshi'=>'全日制','xingbie'=>'男'],
];
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$name = "于楠";
$age =20;
$students=$this->students;
return view('hello')->with(compact('name','age','students'));
dd("hhh");
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
dd("creat");
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
dd("store");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
$stu=null;
$students=$this->students;
// $students=Student::$students;
foreach ($students as $value) {
if($value['xh']==$id){
$stu=$value;
}
}
return view('detail',compact('stu'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
dd("edit:".$id);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function showSome(){
$names="于楠";
return view('hello');
}
}
Hello代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>视图文件</h1>
<table>
</table>
<table border="1">
<tr>
<th>编号</th>
<th>学号</th>
<th>姓名</th>
<th>年级</th>
<th>专业</th>
<th>专业编号</th>
<th>班级</th>
<th>学习形式</th>
<th>性别</th>
</tr>
@foreach ($students as $item )
@if($loop->index%2)
<tr class="bgcolor" algin="center">
@else
<tr algin="center">
@endif
<td>{{$item['id']}}</td>
<td>{{$item['xh']}}</td>
<td>
<a href="{{url('users/'.$item['xh'])}}">
{{$item['xingming']}}
</a>
</td>
<td>{{$item['nianji']}}</td>
<td>{{$item['zhuanye']}}</td>
<td>{{$item['zhuanyebianhao']}}</td>
<td>{{$item['banji']}}</td>
<td>{{$item['xuexixingshi']}}</td>
<td>{{$item['xingbie']}}</td>
</tr>
@endforeach
</table>
<style type="text/css">
.bgcolor{
background-color:lightgreen;
}
</style>
</body>
</html>
detail代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<h2>详细信息</h2>
@if(empty($stu))
没有学生信息
@else
<div>
{{$stu['xh']}}{{$stu['xingming']}}
</div>
@endif
</body>
</html>
运行截图