質問編集履歴

3

form追記

2017/07/13 09:47

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -106,11 +106,21 @@
106
106
 
107
107
  ```view
108
108
 
109
+ <form class="clearfix m-t-50" method="GET" action="{{url('search')}}">
110
+
111
+ <div class="input-group input-group-lg col-sm-offset-2 col-sm-8 p-a-0">
112
+
109
113
  <input type="text" name="q" class="form-control submit13" placeholder="検索語句を入力してください" title="検索語句" value="{{$q or ''}}">
110
114
 
111
115
  <span class="input-group-btn">
112
116
 
113
117
  <button class="btn btn-success" type="submit">検索</button>
118
+
119
+ </span>
120
+
121
+ </div>
122
+
123
+ </form>
114
124
 
115
125
  ```
116
126
 

2

コード追加

2017/07/13 09:47

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -50,6 +50,56 @@
50
50
 
51
51
  $search = isset($input['search']) ? (int)$input['search'] : 0;dd($input['search']);
52
52
 
53
+ if ($search) {
54
+
55
+ $data = Search::select('result', 'query')->where('id', $search)->first();
56
+
57
+ $ids = $data ? $data['result'] : [];
58
+
59
+ $q = isset($data['query']['q']) ? $data['query']['q'] : '';
60
+
61
+ } else {
62
+
63
+ $q = isset($input['q']) ? $input['q'] : '';
64
+
65
+ $query = Fulltext::where('type', '<>', 'job');
66
+
67
+ if ($q !== '') $query->whereIndex($q);
68
+
69
+ if (!is_null($where)) $query->where($where);
70
+
71
+ $ids = NULL;
72
+
73
+ if ($sortFunc) {
74
+
75
+ $query = $query->select('id', 'type', 'main_id')->get()->toArray();
76
+
77
+ usort($query, $sortFunc);
78
+
79
+ $ids = array_pluck($query, 'id');
80
+
81
+ } else {
82
+
83
+ $ids = array_map('intval', $query->orderBy('time','DESC')->lists('id')->toArray());
84
+
85
+ }
86
+
87
+ // $search {{{
88
+
89
+ $search = new Search();
90
+
91
+ $search['result'] = $ids;
92
+
93
+ $search['query'] = ['q' => $q];
94
+
95
+ $search->save();
96
+
97
+ $search = $search['id'];
98
+
99
+ // }}}
100
+
101
+ }
102
+
53
103
  }
54
104
 
55
105
  ```

1

ビューのコードを追加しました。

2017/07/13 09:22

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -54,7 +54,15 @@
54
54
 
55
55
  ```
56
56
 
57
+ ```view
57
58
 
59
+ <input type="text" name="q" class="form-control submit13" placeholder="検索語句を入力してください" title="検索語句" value="{{$q or ''}}">
60
+
61
+ <span class="input-group-btn">
62
+
63
+ <button class="btn btn-success" type="submit">検索</button>
64
+
65
+ ```
58
66
 
59
67
  ###補足情報(言語/FW/ツール等のバージョンなど)
60
68