This package provides an elegant way to sort your model collection by distance.
- Use Composer to add the package to your project:
composer require vedatunlu/order-by-distance
- Add NearestTo trait to the model you want to use in your laravel project.
Important: Your model should have 'latitude' and 'longitude' columns on the database.
Location::nearestTo(41.02488721726937, 29.015275681371868)
->get();
Location::where('title', $title)
->nearestTo(41.02488721726937, 29.015275681371868)
->get();
We welcome and appreciate your contributions to the package! The contribution guide can be found here.
This package is open-sourced software licensed under the MIT license.