This article mainly introduces the Laravel framework implementation of the model layer of the deletion and modification (curd) operation, combined with the example form analysis of the LARAVEL framework model layer for the database to delete and modify the operation of the specific implementation skills, the need for friends can refer to the next
In this paper, the Laravel framework is introduced to implement the model layer's deletion and modification (curd) operation. Share to everyone for your reference, as follows:
protected $table = ' user_city ';p ublic $timestamps = false;//Add return idpublic function Cityadd ($data) {return $this->ins Ertgetid ($data);} Single Lookup public Function Getfind ($id) {if ($this->where (' id ', $id)->first ()) {return $this->where (' id ', $id)-&G T;first ()->toarray (); }else{return []; }}//query user has several UID, return quantity public function countcity ($uid) {if ($this->where (' uid ', $uid)->first ()) {return $this Where (' uid ', $uid)->count (); }else{return []; }}//query all data public function GetAll () {return $this->get ()->toarray ();} /*** Modify Administrator Information * @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; }}//plus conditions, time//Query the subscriber's number of city 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"); Convert a date to a Unix timestamp $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 ');} /*** Find the fortress information by ID only returns the value of a field * @param $id * @return array*/public function Getcityname ($id) {if ($this->where (' city_id '), $i d) {->first ()) {return $this->where (' city_id ', $id)->lists (' city_name ') [0]; }else{return []; }}
Articles you may be interested in:
Thinkphp Framework implements an example of how to export Excel data
Native JS implements an example of how Ajax interacts with PHP via post. PHP tips
Laravel Integration of Geetest Verification code PHP instance