語法 | 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