Blogger Information
Blog 30
fans 0
comment 0
visits 19996
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11月5日作业,练习一下blade模板的语法。如:变量渲染、foreach
人生就像过山车的博客
Original
785 people have browsed it

老师好, 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>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments