好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識(shí)庫 > Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解

Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解

熱門標(biāo)簽:騰訊外呼管理系統(tǒng) 青島語音外呼系統(tǒng)招商 岳陽外呼型呼叫中心系統(tǒng)在哪里 百應(yīng)電話機(jī)器人服務(wù) 揚(yáng)州地圖標(biāo)注app 山西探意電話機(jī)器人 山西回?fù)芡夂粝到y(tǒng) 河南電銷卡外呼系統(tǒng)哪家強(qiáng) 昭通辦理400電話

本文實(shí)例講述了Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作。分享給大家供大家參考,具體如下:

注:以下知識(shí)點(diǎn)可能有不全面之處,望見諒

NO.1Eloquent ORM簡介

Laravel所自帶的Eloquent ORM是一個(gè)優(yōu)美、簡潔的ActiveRecord實(shí)現(xiàn),用來實(shí)現(xiàn)數(shù)據(jù)庫操作
每個(gè)數(shù)據(jù)表都有與之相對(duì)應(yīng)的“模型(Model)”用于和數(shù)據(jù)交互

NO.2模型的建立

最基礎(chǔ)的模型代碼如下:

namespace App;
use Illuminate\Database\Eloquent\Model;
class Student extends Model
{
 //指定表名
 protected $table = 'student';
 //指定id
 protected $primaryKey = 'id';
}

將他創(chuàng)建于app目錄下,命名為Student.php

NO.3查詢數(shù)據(jù)

首先在查詢之前,我先讓你們看一下我的數(shù)據(jù)庫

數(shù)據(jù)如上,然后查詢

1.all方式

代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
 public function orm1()
  {
      $students = Student::all();
      dd($students);
 }
}

顯示數(shù)據(jù)庫里的所有數(shù)據(jù)

2.find方式

代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
 public function orm1()
  {
      $students = Student::find(1);
      dd($students);
 }
}

查找指定數(shù)據(jù)

3.findOrFail方式

代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
 public function orm1()
  {
      $students = Student::findOrFail(1);
      dd($students);
 }
}

如果他沒查到指定的數(shù)據(jù),那么他會(huì)報(bào)錯(cuò),而find若是沒有查到該函數(shù),只會(huì)彈出一個(gè)null

4.查詢構(gòu)造器的使用

  • 1.get方式使用
namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
 public function orm1()
  {
      $students = Student::get();
      dd($students);
 }
}

他會(huì)得到一個(gè)完整的數(shù)據(jù)信息,和原本的意義沒有區(qū)別

  • 2.first方式使用

代碼如下:

namespace App\Http\Controllers;
use App\Student;
use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{
 public function orm1()
  {
     $student = Student::where('id','>',1)
     ->orderBy('age','desc')
     ->first();
     dd($student);
 }
}

當(dāng)id大于一的時(shí)候,獲取一個(gè)最大值的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.聚合函數(shù)的使用

  • 1.count函數(shù)

代碼如下:

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函數(shù)

代碼如下:

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函數(shù)

代碼如下:

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函數(shù)

代碼如下:

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函數(shù)

代碼如下:

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);
 }
}

更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對(duì)大家基于Laravel框架的PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • django框架面向?qū)ο驩RM模型繼承用法實(shí)例分析
  • MySql用DATE_FORMAT截取DateTime字段的日期值
  • mysql數(shù)據(jù)庫中的information_schema和mysql可以刪除嗎?
  • ORM模型框架操作mysql數(shù)據(jù)庫的方法

標(biāo)簽:寶雞 婁底 南陽 湛江 宜賓 黃南 銅川 鎮(zhèn)江

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解》,本文關(guān)鍵詞  Laravel,框架,Eloquent,ORM,簡介,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 午夜高清啪啪免费观看完整| 最好看的免费观看视频| 欧美成人精品aV在线观看图图破| 日韩亚洲欧美香蕉精品区| 黄色三级视频在线| 女女?互慰吃奶互揉的视频 | chinese东北痞子gay| 免费无遮挡????| 黃色A片三級三級三級免费看精东| 性色| 耻辱の女教师大桥未久| 国产精品婬乱一区二区三区视频| 日韩精品无码一区二区河北彩花| 女人18毛片a级毛片| 久久久久久精品免费看sss| 冲田杏梨午夜久久99视| 日韩毛片免费视频一级特黄| 国语对白91爽死我了| 多肉文| 久久久加勒比无码一区| 成视人A片产无码免费视频看A片| 免费看欧美一级特黄α大片| 澡堂老板家的男人们| 男生女生搞黄色| 精产国品一二三区别9977漫画| 天使直播| 重口XXOO变态另类毛片| 女生的逼app| 看美女奶水直播的软件| 久久水蜜桃亚洲AV无码精品 | 二男操一女| 亚洲风影视传媒有限公司| 日韩中文字幕精品无码亚洲幕空4| 英语老师撕开丝袜让我爽| 国产色妞妞在线观看| 波多野结衣被义子侵犯| 国产高潮好紧好爽受不了了小说 | 国产精品人妻熟女毛片A片骨灰盒 人妻久久澡久久看久久摸九九九 福利一区福利二区微拍刺激 | 国产精品视频一区二区三区九县| 男人舔女人下面视频免费| 免费啪啪网站|