Example #1
0
 public function buildShopsListQuery()
 {
     $this->qry = ShopDetails::Select('shop_name', 'shop_details.url_slug', 'shop_details.id', 'shop_city', 'shop_state', 'shop_country', 'users.first_name', 'users.last_name', 'shop_details.user_id', 'users_shop_details.total_products')->join('users', function ($join) {
         $join->on('users.id', '=', 'shop_details.user_id');
     });
     $this->qry->join('users_shop_details', function ($join2) {
         $join2->on('users_shop_details.user_id', '=', 'shop_details.user_id');
     });
     if ($this->getSrchVal("owner_name") != "") {
         $name_arr = explode(" ", $this->getSrchVal('owner_name'));
         if (count($name_arr) > 0) {
             foreach ($name_arr as $names) {
                 $this->qry->whereRaw("( users.first_name LIKE  '%" . addslashes($names) . "%' OR users.last_name LIKE  '%" . addslashes($names) . "%')");
             }
         }
     }
     if ($this->getSrchVal("shop_name") != "") {
         $shop_name = $this->getSrchVal("shop_name");
         //Input::get("shop_name"); //edited by mohamed_158at11
         $s_name_arr = explode(" ", $shop_name);
         if (count($s_name_arr) > 0) {
             foreach ($s_name_arr as $names) {
                 $this->qry->WhereRaw("(shop_name LIKE '%" . addslashes($names) . "%')");
             }
         }
     }
     //$this->qry->Where('users.shop_status', 1);
     //$this->qry->Where('users.is_shop_owner', 'Yes');
     $this->qry->groupBy('shop_details.id');
     $this->qry->orderBy('users_shop_details.total_products', 'DESC');
     return $this->qry;
 }