Laravel Framework search function Implementation code

Source: Internet
Author: User
This article is mainly to share with you laravel framework search function implementation code, hope to help everyone. The search function here is mainly based on the form get submission implementation.

<form action= "/backend/auditlist" method= "get" >  <table class= "Search_tab" >    <tr>      <th width= > select category:</th>      <td>        <select Name= "class" >          <option value= "" > All </option>          @foreach ($category as $c)            <option value= "{{$c->id}}" >{{$c->class_name}}< /option>          @endforeach        </select>      </td>      <th width= "All" > article title:</th>      <!--query keywords--      <td><input type= "text" name= "keywords" placeholder= "article title" ></td>      <td><input type= "Submit" Name= "sub" value= "Query" ></td>    </tr>  </table> </form>

PHP Partial logic

Public Function Article_list () {//echo ' zoule '; exit; test whether the form into the method of everyone to write $shownum = 1; if (array_key_exists (' class ', $_get) | |    Array_key_exists (' keywords ', $_get)) {//echo ' 111 '; if ($_get[' class ')} {//article Model Leftjoin table Join query executes $postdata = article::leftjoin (' Category ', function ($joi) based on these fields in both tables     N) {$join->on (' article.class_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_ Time '])->where (' article.class_id ', ' = ', $_get[' class '))->orderby (' Release_time ', ' desc ')->paginate ($   Shownum); }elseif ($_get[' keywords ')) {$postdata = Article::leftjoin (' Category ', function ($join) {$join->on (' Article.cla     ss_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_ Time '])->where (' article.title_editing ', ' = ', $_get[' keywords '])->orderby (' Release_time ', ' desc ')       Paginate ($shownum); }else{$pOstdata = article::leftjoin (' Category ', function ($join) {$join->on (' article.class_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_   Time '])->orderby (' Release_time ', ' desc ')->paginate ($shownum);   }}else{//echo ' 2222 ';   $postdata = article::leftjoin (' Category ', function ($join) {$join->on (' article.class_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_  Time '])->orderby (' Release_time ', ' desc ')->paginate ($shownum);  }//The category ID is not the parent id $category = db::table (' category ')->where (' parent_id ', '! = ', ' 0 ')->get (); Render the page pass parameter return view (' Backend.article_list ', [' postdata ' = ' $postdata, ' shownum ' = ' $shownum, ' category ' =>$ Category]);}

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.