佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > Laravel框架實(shí)現(xiàn)model層的增刪改查(CURD)操作示例

Laravel框架實(shí)現(xiàn)model層的增刪改查(CURD)操作示例

熱門標(biāo)簽:團(tuán)購網(wǎng)站 Linux服務(wù)器 Mysql連接數(shù)設(shè)置 銀行業(yè)務(wù) 服務(wù)器配置 電子圍欄 科大訊飛語音識別系統(tǒng) 阿里云

本文實(shí)例講述了Laravel框架實(shí)現(xiàn)model層的增刪改查(CURD)操作。分享給大家供大家參考,具體如下:

protected $table = 'user_city';
public $timestamps = false;
//添加 返回id
public function cityadd($data)
{
    return $this->insertGetId($data);
}
//單條查找
public function getfind($id)
{
    if($this->where('id',$id)->first()){
      return $this->where('id',$id)->first()->toArray();
    }else{
      return [];
    }
}
//查詢用戶有幾個uid,返回數(shù)量
public function countCity($uid){
    if($this->where('uid',$uid)->first()){
      return $this->where('uid',$uid)->count();
    }else{
      return [];
    }
}
//查詢?nèi)繑?shù)據(jù)
public function getAll()
{
    return $this->get()->toArray();
}
/**
* 修改管理員信息
* @param $id
* @param $data
* @return bool
*/
public function upAdmin($id,$data)
{
    if($this->find($id)){
      return $this->where('id',$id)->update($data);
    }else{
      return false;
    }
}
//加條件,時間
//查詢用戶的認(rèn)購的城數(shù)
public function buy_num($uid){
    $startDate = date('Y-m-01', strtotime(date("Y-m-d")));
    $endDate = date('Y-m-d', strtotime("$startDate +1 month -1 day"));
    // 將日期轉(zhuǎn)換為Unix時間戳
    $endDate=$endDate." 22:59:59";
    $startDateStr = strtotime($startDate);
    $endtDateStr = strtotime($endDate);
    return $this->where('uid',$uid)->where('buy_type',1)->whereBetween('create_time', array($startDateStr,$endtDateStr))->sum('buy_num');
}
/**
* 根據(jù)id查找城池信息 只返回某個字段的值
* @param $id
* @return array
*/
public function getCityName($id)
{
    if($this->where('city_id',$id)->first()){
      return $this->where('city_id',$id)->lists('city_name')[0];
    }else{
      return [];
    }
}

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

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

您可能感興趣的文章:
  • Laravel5.1 框架數(shù)據(jù)庫查詢構(gòu)建器用法實(shí)例詳解
  • laravel框架數(shù)據(jù)庫操作、查詢構(gòu)建器、Eloquent ORM操作實(shí)例分析
  • laravel通用化的CURD的實(shí)現(xiàn)
  • Laravel框架查詢構(gòu)造器 CURD操作示例
  • Laravel框架數(shù)據(jù)庫CURD操作、連貫操作總結(jié)
  • laravel5.6 框架操作數(shù)據(jù) Eloquent ORM用法示例
  • laravel 操作數(shù)據(jù)庫常用函數(shù)的返回值方法
  • laravel框架數(shù)據(jù)庫配置及操作數(shù)據(jù)庫示例
  • laravel5.6框架操作數(shù)據(jù)curd寫法(查詢構(gòu)建器)實(shí)例分析

標(biāo)簽:蚌埠 衡水 江蘇 衢州 棗莊 廣元 大理 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel框架實(shí)現(xiàn)model層的增刪改查(CURD)操作示例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    壤塘县| 安陆市| 台州市| 克什克腾旗| 沾益县| 闸北区| 蓝田县| 武汉市| 洮南市| 平远县| 永清县| 咸宁市| 喀什市| 西宁市| 蚌埠市| 色达县| 湄潭县| 大邑县| 达尔| 柏乡县| 大英县| 铜梁县| 缙云县| 建德市| 连城县| 出国| 兰考县| 遂川县| 镶黄旗| 伊宁县| 高邑县| 保定市| 南平市| 柳河县| 榆林市| 庐江县| 威信县| 玛纳斯县| 漯河市| 万盛区| 射洪县|