语法 | array select(string $query, array $bindings = array()) |
---|---|
参数 |
|
返回值 | array |
描述 |
在数据库上运行 select 语句
|
php artisan make:controller StudViewController
第3步 - 将以下代码复制到文件 - app/Http/Controllers/StudViewController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; use App\Http\Requests; use App\Http\Controllers\Controller; class StudViewController extends Controller { public function index(){ $users = DB::select('select * from student'); return view('stud_view',['users'=>$users]); } }
resources/views/ stud_view.blade.php
<html> <head> <title>查看学生列表</title> </head> <body> <table border = 1> <tr> <td>编号ID</td> <td>名字</td> <td>年龄</td> </tr> @foreach ($users as $user) <tr> <td>{{ $user->id }}</td> <td>{{ $user->name }}</td> <td>{{ $user->age}}</td> </tr> @endforeach </table> </body> </html>
第5步 - 添加以下行到 app/Http/routes.php
Route::get('view-records','StudViewController@index');
http://localhost:8000/view-records