1. 程式人生 > >[2018-01-12] laravel--ORM

[2018-01-12] laravel--ORM

key names namespace ace table end all 方法 默認

建立模型

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;

class Student extends Model
{

    //數據表默認對應的是模型的復數
    //指定表名
    protected $table = ‘student‘;

    //指定ID
    protected $primaryKey = ‘id‘;

}

在控制器當中書寫一個方法

use App\Student; //引入模型

public
function orm1() { $students = Student::all(); //
查詢所有數據 dd($students); }

[2018-01-12] laravel--ORM