Smsma
7 months ago

Call to a member function paginate() on string

Posted 7 months ago by Smsma

what is the wrong here !!

public function search(Request $request) {
        $rules = [
            'name'   => 'max:191',
            'city'   => '',
            'lat'    => '',
            'lang'   => '',
            'price_from'=> 'numeric',
            'price_to'  => 'numeric',
            'area_from' => 'numeric',
            'area_to'   => 'numeric',
            'num_of_person_from'=> 'numeric',
            'num_of_person_to'  => 'numeric',
           
        ];

        $validator = Validator::make($request->all(), $rules);

        if ($validator->fails())
            return ApiController::respondWithError(validateRules($validator->errors(), $rules));
            
        $gr_circle_radius = 6371;
        $max_distance = 2;
        $city =  $request->city;
        $name =  $request->name;
        $price_from =  $request->price_from;
        $price_to =  $request->price_to;
        $area_from =  $request->area_from;
        $area_to =  $request->area_to;
        $num_of_person_from =  $request->num_of_person_from;
        $num_of_person_to =  $request->num_of_person_to;
        $lat =  $request->lat;
        $lang =  $request->lang;
        
        $query = '';
    
        if($city)
        $query .= "->where('city' ,'like', '%' . $city . '%')";
        
        elseif($name)
        $query .= "->where('name' ,'like', '%' . $name . '%')";
        
        elseif($price_from && $price_to)
            $query .= "->whereBetween('price', [$request->price_from, $request->price_to])";
         
    
        elseif($area_from && $area_to)
            $query .= "->whereBetween('area', [$request->area_from, $request->area_to])";
        
        elseif($num_of_person_from && $num_of_person_to)
            $query .= "->whereBetween('person_count', [$request->num_of_person_from, $request->num_of_person_to])";

        elseif($lat)
        $query .= "select(DB::raw('*,
                            ($gr_circle_radius * ACOS(COS(RADIANS($lat))
                                * COS(RADIANS(lat))
                                * COS(RADIANS($lng) - RADIANS(lang))
                                + SIN(RADIANS($lat))
                                * SIN(RADIANS(lat)))) AS distance')
                )->orderBy('distance','asc')
                    ->having('distance', '<', $max_distance)";
        
        $data = DB::table('holes').$query->paginate(10);  
        ```

Please sign in or create an account to participate in this conversation.