张云琪 4.31作业

这是一个关于 Laravel 框架中 UserController 类的代码示例,展示了如何从控制器向视图传递数据并渲染。index 方法用于显示学生信息,show 方法根据ID获取并展示详细信息。视图文件 'info.blade.php' 是一个表格,显示了学生列表,每个学生信息包括姓名、年级等。此外,还有其他CRUD操作的方法定义。
摘要由CSDN通过智能技术生成

效果图片

在这里插入图片描述
在这里插入图片描述

UserController.php代码

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Student;

class UserController extends Controller
{

    
    public function index()
    {
       $name = "张云琪";
       $age =19;
    //    $students=$this->students;
    $students = Student::$students;
       return view('info')->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)
    {
        //
    }

    /**
     * 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)
    {
        //
    }

    /**
     * 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('admin.login')->with('name',$names)->with('age',20);
    }
}

info.blade.php

<!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">
    <link rel="stylesheet" type="text/css" href="{{asset('').'css/bootstrap.min.css'}}">
    <title>Document</title>
</head>
<body>
<table class="table table-sm">
  <thead>
    <tr>
      <th scope="col">编号</th>
      <th scope="col">姓名</th>
      <th scope="col">年级</th>
      <th scope="col">专业</th>
      <th scope="col">专业编号</th>
      <th scope="col">班级</th>
      <th scope="col">学习形式</th>
      <th scope="col">性别</th>              
    </tr>       
  </thead>
  <tbody>
    @foreach ($students as $item )
    @if ($loop->index%2)
    <tr class="bgcolor">
        @else
        <tr>
        
    @endif

    <!-- <tr> -->
      <th scope="row">{{$loop->index}}{{$item['id']}}</th>

      
             <td>     
            <!-- <a href="{{url('useer/'.$item['xh'])}}">{                {$item['xingming']}}</a> -->
            <a href="{{route('useer.show',$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
    <style type="text/css">
        .bgcolor{
            background: lightgreen;

        }
    </style>
</body>
</html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值