博主信息
人生就像过山车的博客
博文
30
粉丝
0
评论
0
访问量
9394
积分:0
P豆:69

11月5日作业,练习一下blade模板的语法。如:变量渲染、foreach

2020年03月15日 07:11:34阅读数:277博客 / 人生就像过山车的博客/ 作业

老师好, 11月5日作业,练习一下blade模板的语法。如:变量渲染、foreach。 最近事很多,比较忙,但是还是会忙里偷闲看录播以及补写作业的,老师辛苦了,感恩感恩,虽然我进度落下来了,但是还会抽空推进,该做的作业,该交的毕设计都不会少的。

ZY01.jpg

Controller:

namespace App\Http\Controllers;

use App\Models\Lite;

use Illuminate\Support\Facades\DB;

class Home2 extends Controller
{

public function index(Lite $lite)
    {

        $data['list'] = $lite->getAll();



        return view('db', $data);
        
        }
        
 }
        
Model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Lite extends Model{

        protected $table = 'lite';

        protected $primaryKey = 'id';

        public function getAll(){

            //return $this->get()->toArray();

            return $this->get()->all();

            //return $res = \DB::table('lite')->get();
        }
}

View:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<table border="1" cellspacing="0" align="center">
    <tr bgcolor="#faebd7">
        <th>ID</th>
        <th>NAME</th>
        <th>DESCRIPTION</th>
        <th>PRICE</th>

    </tr>

 @foreach($list as $li)
 <tr>
        <td>{{ $li->id }}</td>
        <td>{{ $li->name }}</td>
        <td>{{ $li->description }}</td>
        <td>{{ $li->price }}</td>
        </tr>
 @endforeach

</table>
</body>
</html>

版权申明:本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!

全部评论

文明上网理性发言,请遵守新闻评论服务协议

条评论