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

 $providers= Provider::query();

        $providers = $providers->get();
       
        foreach($providers as $provider)
        {
            $provider->distance = $this->addDistanceToProvider($provider,$request);
       
        }
      $providers->sortBy('distance');
      dd($providers);

How I can sort is by distance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire