Laravel框架Eloquent ORM简介、模型建立及查询数据操(2)
当id大于一的时候,获取一个最大值的age
- 3.where方式使用
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::where('id','>',1) ->get(); dd($student); } }
- 4.chunk方式使用
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::chunck(2,function($student){ var_dump($student); }); } }
5.聚合函数的使用
- 1.count函数
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::count(); dd($student); } }
- 2.max函数
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::max('age'); dd($student); } }
- 3.min函数
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::min('age'); dd($student); } }
- 4.avg函数
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::avg('age'); dd($student); } }
- 5.sum函数
代码如下:
namespace App\Http\Controllers; use App\Student; use Illuminate\Support\Facades\DB; class StudentController extends Controller { public function orm1() { $student = Student::sum('age'); dd($student); } }
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。