Laravel Common Query

Source: Internet
Author: User
The manual is simple enough to handle the queries we may use daily:

$oSpecialty = new Specialty (),//dd (Specialty::where (' id ', 3)->value (' path ')),//Query a single field, Return String//dd (specialty: : Where (' ID ', 3)->first ([' id ', ' pid ', ' Path ')),//query multiple defined fields//dd (specialty::where (' pid ', 0)->get ([' id ', ' pid ', ' Path ']);//Querying multiple fields consisting of a dataset//dd (Specialty::where (' pid ', 0)->lists (' id '));//Querying a collection of columns, and returning the result key is the set DD with the 0,1,2 value as the ID ( Specialty::where (' pid ', 0)->skip (5)->take (+)->get ());//query Limit number of records//DD (Db::update (' Update users set Name= ') Neo2 "where id=1200 '));//Original Ecological update

Another example:

$userModel = new User (), $info 1=user::where (' id ', 1)->get (); $info 2=user::find (1); $info 3=user::whereid (1) First (); $info 4=user::where (' id ', 1)->first (); $info 5 = User::where ([' ID ' =>1, ' email ' = ' admin@163.com '])- >first ();//Multiple Conditions $info6 = User::whereid (1)->first ();//Use where+ Key name to query $info7 = User::where ([' ID ' =>1])->first (); $info 8 = User::where ([' ID ' =>1])->first ()->toarray ();//Note that the ToArray object is null to give an error, so it is generally not used $info9 = Userbind:: where ([' Fromid ' =>1])->get ()->toarray ();//Notice that the ToArray object is null will error, so it is generally not used

More examples

User::wherein (' id ', $id)->delete ();//need to be aware that $id is an array, not a comma-linked string Teacher::wherein (' user_id ', $id)->delete (); /delete Teacher's Watch
  • 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.