您好,登錄后才能下訂單哦!
這篇文章給大家介紹使用Laravel怎么對model層進(jìn)行增刪改查操作,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
具體如下:
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 []; } }
Laravel 是一套簡潔、優(yōu)雅的PHP Web開發(fā)框架。它可以讓你從面條一樣雜亂的代碼中解脫出來;它可以幫你構(gòu)建一個完美的網(wǎng)絡(luò)APP,而且每行代碼都可以簡潔、富于表達(dá)力。
關(guān)于使用Laravel怎么對model層進(jìn)行增刪改查操作就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。