samedi 5 décembre 2020

How to sort object in laravel

I am fetching data from database. then I am adding new value in that object. after that i am trying to sort object that value but it is not working

Here is the code

   public function search(Request $request)
    {
 

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

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

    }

How I can sort is by distance



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/36Qqhe1
via IFTTT

Aucun commentaire:

Enregistrer un commentaire