<?php namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { //DB facade原始SQL语句 public function test1() { $students = DB::select('select * from student'); //var_dump($students)…
现在有查询语句: SELECT users.sNmame, users.iCreateTime, users_ext.iAge, users_ext.sSex FROM users LEFT JOIN users_ext ON users.iAutoId = users_ext.iUserID WHERE users.iStatus ORDER BY users.iCreateTime LIMIT , 这里是简单的一个查询语句,接下来就以ORM的形式实现: public function get…
简介 其实大家都知道,数据表之间都是可以关联的,前面讲过了,Eloquent ORM是数据模型操作代替表操作,那么表的关联查询,在Eloquent这里也就是模型间的关联查询,这就是本章的主要内容: Eloquent一个支持以下6种表间关系: One To One(一对一) One To Many(一对多) Many To Many(多对多) Has Many Through(跨表一对多) Polymorphic Relations(belongsTo多态) Many To Many Polymo…