Object of class Closure could not be converted to int in laravel

60 Views Asked by At

am trying to paginate the results of the filter function but am getting this error Object of class Closure could not be converted to int. The function works this way upon selecting an option all the houses which hs those tags are shown.am achieving this using ajax,laravel and jquery.i have been able to do this but the issue am getting is when i try to paginate the results usingthis function i get the above error.here is my function in the view where am calling the paginate function

$(document).on('click', '.pagination a', function(event){
 event.preventDefault();
 var page = $(this).attr('href').split('page=')[1];
 getMoreHouses(page);
});

//function for getting the results from the response and adding them to the pages in the pagination 

function getMoreHouses(page)
        {
            var hseurl=$("#url").val();
            var hsetag = $('input[class^="tagtitle"]').filter(":checked").val();

            $.ajax({
                type:"GET",
                url:'{{ route("rentalcategory.get-more-houses") }}' + "?page=" + page,
                data:{
                    url:hseurl,
                    rentaltag:hsetag,

                },
                success:function(data)
                {
                    $('.showrentalhouses').html(data);
                }
            })
        }
        

here is my function in the controller

 public function get_more_houses(Request $request)
{
    if($request->ajax()){

        $hsedata=$request->all();

        $rentalcaturl=$hsedata['url'];
        
        $rentalcatcount=Rental_category::where(['rentalcat_url'=>$rentalcaturl,'status'=>1])->count();

        if($rentalcatcount>0){

            $rentalcategorydetails=Rental_category::rentalcategorydetails($rentalcaturl);

            $housescategory=Rental_house::whereIn('rentalcat_id',$rentalcategorydetails['catids'])
            ->where(['rental_status'=>1,'is_extraimages'=>1,'is_rentable'=>1])->orderby('id','DESC')->paginate(4);
            $rentalcategories=Rental_category::withCount('rentalhses')->get();

            $rentaltags=Rental_tags::with('tagshouse')->get();

            $rentallocations=Location::where(['status'=>1])->get();

            // get the rental tag results into a pagination

            if(isset($hsedata['rentaltag']) && !empty($hsedata['rentaltag'])){

                $hsetag_id = $hsedata['rentaltag'];

                    
                $housescategory
                    ->whereIn('id', function($q) use ($hsetag_id)
                {
                    $q
                    ->select('rental_id')
                    ->from('rentalhouse_tags')
                    ->where('tag_id', $hsetag_id);
                });

                
            }
        
            return view('Front.Rentalslisting.rentalhsesjson',compact('rentalcaturl','rentallocations','rentalcatcount','rentalcategorydetails','rentaltags','housescategory','rentalcategories'))->render();
        }
    }
}

how can i work out this one

1

There are 1 best solutions below

0
Khang Tran On BEST ANSWER

You should call paginate method at the bottom of the function:

public function get_more_houses(Request $request)
{
    if($request->ajax()){
        $hsedata = $request->all();

        $rentalcaturl = $hsedata['url'];

        $rentalcatcount = Rental_category::where(['rentalcat_url'=>$rentalcaturl,'status'=>1])->count();

        if ($rentalcatcount>0){

            $rentalcategorydetails = Rental_category::rentalcategorydetails($rentalcaturl);

            $housescategoryQuery = Rental_house::whereIn('rentalcat_id',$rentalcategorydetails['catids'])
                ->where(['rental_status'=>1,'is_extraimages'=>1,'is_rentable'=>1]);
            
            $rentalcategories=Rental_category::withCount('rentalhses')->get();

            $rentaltags=Rental_tags::with('tagshouse')->get();

            $rentallocations=Location::where(['status'=>1])->get();

            // get the rental tag results into a pagination

            if(isset($hsedata['rentaltag']) && !empty($hsedata['rentaltag'])){

                $hsetag_id = $hsedata['rentaltag'];
                
                $housescategoryQuery
                    ->whereIn('id', function($q) use ($hsetag_id)
                    {
                        $q
                            ->select('rental_id')
                            ->from('rentalhouse_tags')
                            ->where('tag_id', $hsetag_id);
                    });


            }

            $housescategory = $housescategoryQuery->orderby('id','DESC')->paginate(4);

            return view('Front.Rentalslisting.rentalhsesjson',compact('rentalcaturl','rentallocations','rentalcatcount','rentalcategorydetails','rentaltags','housescategory','rentalcategories'))->render();
        }
    }
}