samedi 5 décembre 2020

Ajax response is not returning in sorted form laravel controller

I am fetching data from database then adding one more property to that object which is distance. and sorting object data based on that property. When I dd() it in controller to check if data is sorted or not. I see that data is sorted but when I return it as JSON response it returned as it comed from database.

controller function


 public function search(Request $request)
    {
 

    $providers = Provider::get()->map(function($item) use($request){
        $item->setAttribute('distance',$this->addDistanceToProvider($item,$request)) ;
        return $item;
    })->sortBy('distance');

    dd($providers);
        return response()->json($providers);

    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire