Implementation of search functions in the laravel framework

Source: Internet
Author: User

Implementation of search functions in the laravel framework

The search function is mainly implemented based on form get submission.

<Form action = "/backend/auditList" method = "get"> <table class = "search_tab"> <tr> <th width = "120"> select a 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 = "70"> Article Title: </th> <! -- Query Keyword --> <td> <input type = "text" name = "keywords" placeholder = "article title"> </td> <input type = "submit "name =" sub "value =" query "> </td> </tr> </table> </form>

Php Logic

Public function article_list () {// echo 'zoule'; exit; test whether the form is written into the method. $ shownum = 1; if (array_key_exists ('class ', $ _ GET) | array_key_exists ('keyword', $ _ GET) {// echo '000000'; if ($ _ GET ['class']) {// The Article model leftJoin table connection query executes $ postdata = Article: leftJoin ('category ', function ($ join) based on the fields in the two tables) {$ join-> on ('Article. class_id ',' = ', 'category. id');})-> select (['Article. id', 'category. class_name ', 'Article. s Tatus ', 'Article. title_editing ', 'Article. update_time '])-> where ('Article. class_id ',' = ', $ _ GET ['class'])-> orderBy ('release _ time', 'desc')-> paginate ($ shownum );} elseif ($ _ GET ['keyword']) {$ 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_tim E '])-> where ('Article. title_editing ',' = ', $ _ GET ['keyword'])-> 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);} el Se {// echo '000000'; $ 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 (); // The 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.