1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Helpers\CryptoHelper;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
class SearchController extends Controller {
/**
* Shows the index page.
*
* @return Response
*/
public function showPage(Request $request) {
/*
* Sorting
*/
$sort_by = Input::get("sort");
switch ($sort_by) {
case("price"):
$sort_by = "discounted_price";
break;
case("discounted_price"):
$sort_by = "discounted_price";
break;
case("name"):
$sort_by = "name";
break;
case("shop"):
$sort_by = "shop";
break;
case("procent"):
$sort_by = "procent";
break;
case("time"):
$sort_by = "created_at";
break;
case("created_at"):
$sort_by = "created_at";
break;
default:
$sort_by = "created_at";
break;
}
$order_by = $request->input("order");
if ( "desc" != $order_by ) {
$order_by = "asc";
}
$query = Input::get("q");
$q = "%" . $this->escapeLike($query) . "%";
$data = DB::table('all_view')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orderBy($sort_by, $order_by)->simplePaginate(20);
#$data = DB::table('whisky_view')->orderBy('procent', 'DESC')->limit(100)->simplePaginate(20);
#var_dump($data); exit;
$query_string = "";
$query_params = Input::get();
foreach( $query_params as $key => $value) {
$query_string .= "&" . $key . "=" . $value;
}
$query_string = ltrim($query_string, "&");
return view('search', ['data' => $data, 'search_phrase' => $query, 'rss_feed' => '/search/feed/?' . $query_string ]);
}
private function escapeLike($string) {
$search = array('%', '_');
$replace = array('\%', '\_');
return str_replace($search, $replace, $string);
}
}
|