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]);}