public function Search($result) { $temp = Product::where('is_published', '=', '1')->with('categories')->with('customfields')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id'); $temp2 = Product::where('is_published', '=', '1')->with('categories')->with('customfields')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id'); $this->page['issearch'] = false; if (isset($_GET["query"])) { $this->page['issearch'] = true; $this->page['myquery'] = $_GET["query"]; $q = $_GET["query"]; $query = new Task(); $query->quary = $q; $query->save(); $this->page['queryterm'] = $q; $searchTerms = explode(' ', $q); $temp2->where(function ($query) use($q) { $query->orWhere('slug', 'LIKE', '%' . trim($q) . '%')->orWhere('title', 'LIKE', '%' . trim($q) . '%')->orWhere('description', 'LIKE', '%' . trim($q) . '%'); }); $temp->where(function ($query) use($searchTerms) { foreach ($searchTerms as $term) { if ($term != '' || $term != null) { $query->orWhere('slug', 'LIKE', '%' . $term . '%')->orWhere('title', 'LIKE', '%' . $term . '%')->orWhere('description', 'LIKE', '%' . $term . '%'); } } }); $this->page['searchresults'] = 0; if (sizeof($temp2->get()) > 0) { $result = $temp2; $this->page['searchresults'] = sizeof($temp2->get()); } elseif (sizeof($temp->get()) > 0) { $result = $temp; $this->page['searchresults'] = sizeof($temp->get()); } } return $result; }
function AlaxSearch($result, $ajaxsearch) { Session::put("searchtype", 'ajax'); $temp = Product::where('is_published', '=', '1')->with('categories')->with('customfields')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id'); $temp2 = Product::where('is_published', '=', '1')->with('categories')->with('customfields')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id'); $this->page['issearch'] = false; // trigger_error('error'); $this->page['issearch'] = true; $this->page['myquery'] = $ajaxsearch; $q = $ajaxsearch; $query = new Task(); $query->quary = $q; $query->save(); $this->page['queryterm'] = $q; $searchTerms = preg_split("/(,| )/", $q); // explode(',', $q); $temp2->where(function ($query) use($q) { $query->orWhere('slug', 'LIKE', '%' . trim($q) . '%')->orWhere('title', 'LIKE', '%' . trim($q) . '%')->orWhere('description', 'LIKE', '%' . trim($q) . '%'); }); $temp->where(function ($query) use($searchTerms) { foreach ($searchTerms as $term) { if ($term != '' || $term != null) { $query->orWhere('slug', 'LIKE', '%' . trim($term) . '%')->orWhere('title', 'LIKE', '%' . trim($term) . '%')->orWhere('description', 'LIKE', '%' . trim($term) . '%'); } } }); $this->page['searchresults'] = 0; if (sizeof($temp2->get()) > 0) { $result = $temp2; $this->page['searchresults'] = sizeof($temp2->get()); } elseif (sizeof($temp->get()) > 0) { $result = $temp; $this->page['searchresults'] = sizeof($temp->get()); } return $result; }