Laravel Framework implementation of the model layer of additions and deletions to change the operation example

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.