I got this:
$companies = Company::all();
foreach($companies as $company)
{
$company->distance = distance(); // a float type. My custom field.
}
$companies->sort(function ($a, $b){
return strcmp($a->distance, $b->distance);
})->values()->all();
I've also tried:
$companies->sortBy('distance')
And some other ways that didn't work.
Anyone has any idea on how to accomplish this? Thanks
Okay, I figured it out.
I guess it needs a buffer when it sorts.