thomsult / laravel-mapbox
Laravel package pour les appels API Mapbox (geocoding, directions, etc.)
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/thomsult/laravel-mapbox
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/cache: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- orchestra/testbench: ^10.6
Requires (Dev)
- mockery/mockery: ^1.6
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
This package is auto-updated.
Last update: 2026-01-07 10:31:30 UTC
README
Un package Laravel élégant et typé pour intégrer les APIs Mapbox (geocoding, search, directions) dans vos applications Laravel.
✨ Fonctionnalités
- 🎯 API typée - Auto-complétion complète et type safety
- 🚀 Fluent API - Interface intuitive
- 🔧 Configuration simple - Prêt à l'emploi en quelques minutes
- 📍 Support complet - Search Box API, Geocoding API
- ⚡ Laravel intégré - Service Provider, Facade, Configuration, Cache, Rate Limiting, Lock
- 🧪 Testé - Tests unitaires et d'intégration
📋 Prérequis
- PHP 8.1+
- Laravel 12.0+
- Token d'accès Mapbox
🚀 Installation
Installez le package via Composer :
composer require thomsult/laravel-mapbox
Publiez le fichier de configuration :
php artisan vendor:publish --provider="Thomsult\LaravelMapbox\Providers\MapboxServiceProvider" --tag="config"
Ajoutez votre token Mapbox dans votre fichier .env :
MAPBOX_ACCESS_TOKEN=votre_token_mapbox_ici
🔧 Configuration
Le fichier de configuration config/mapbox.php permet de personnaliser :
return [ 'access_token' => env('MAPBOX_ACCESS_TOKEN'), 'base_uri' => 'https://api.mapbox.com/', 'debug' => env('MAPBOX_DEBUG', false), 'cache' => [ 'enabled' => env('MAPBOX_CACHE_ENABLED', true), 'duration' => env('MAPBOX_CACHE_DURATION', 15), 'timeout' => env('MAPBOX_CACHE_TIMEOUT', 5) ], 'rate' => [ 'enabled' => env('MAPBOX_RATE_ENABLED', true), 'limit' => env('MAPBOX_RATE_LIMIT', 60), 'decay' => env('MAPBOX_RATE_DECAY', 60), ], 'search' => [ 'api_version' => 'v1/', 'prefix' => 'search/', 'base_endpoint' => 'searchbox/', 'forward_endpoint' => 'forward', 'suggest_endpoint' => 'suggest', 'retrieve_endpoint' => 'retrieve', 'category_endpoint' => 'category', 'category_list_endpoint' => 'list/category', 'reverse_endpoint' => 'reverse', ], 'geocoding' => [ 'api_version' => 'v6/', 'prefix' => 'search/', 'base_endpoint' => 'geocode/', 'forward_endpoint' => 'forward', 'reverse_endpoint' => 'reverse', 'batch_endpoint' => 'batch' ] ];
📖 Utilisation
Recherche de base
Artisan::command('mapbox:search {query}', function ($query) { $this->comment('Mapbox search command'); $response = MapboxClient::client() ->autocomplete(fn($req) => $req ->query($query) ->options(fn($options) => $options ->types([PlaceType::PLACE->value]) ->limit(2) ->country('FR') ->language('fr'))) ->call(); }); dd($response); // Affiche la réponse de l'API
Recherche inversée
Artisan::command('mapbox:search:reverse {longitude} {latitude}', function (string $longitude, string $latitude) { $this->comment('Mapbox search command'); $response = MapboxClient::client()->reverse( fn($req) => $req ->longitude($longitude) ->latitude($latitude) ->options( fn($options) => $options ->language('fr') ) ) ->call(); dd($response); });
Recherche Groupée
Artisan::command('mapbox:geocoding:batch', function () { $this->comment('Mapbox search command'); $response = MapboxClient::client()->batch( fn($req) => $req ->body( fn($body) => $body ->add( (new ForwardTextRequest()) ->query("1600 Pennsylvania Avenue NW, Washington, DC 20500, United States") ->options( fn($options) => $options ->types("address") ->bbox("-80, 35, -70, 40") ->limit(1) ) ) ->add( (new ForwardTextRequest()) ->query("1605 Pennsylvania Avenue NW, Washington, DC 20500, United States") ->options( fn($options) => $options ->types("address") ->bbox("-80, 35, -70, 40") ->limit(1) ) ) ) ) ->call(); });
Types de lieux disponibles
use Thomsult\LaravelMapbox\Enums\PlaceType; case COUNTRY = 'country'; case REGION = 'region'; case POSTCODE = 'postcode'; case DISTRICT = 'district'; case PLACE = 'place'; case CITY = 'city'; case LOCALITY = 'locality'; case NEIGHBORHOOD = 'neighborhood'; case STREET = 'street'; case ADDRESS = 'address'; case POI = 'poi'; case CATEGORY = 'category'; case UNKNOWN = 'unknown';
Utilisation dans des commandes Artisan
Artisan::command('mapbox:search {query}', function ($query) { $this->comment('Mapbox search command'); $response = MapboxClient::client() ->autocomplete(fn($req) => $req ->query($query) ->options(fn($options) => $options ->types([PlaceType::PLACE->value]) ->limit(2) ->country('FR') ->language('fr'))) ->call(); });
🧪 Tests
Tests unitaires
composer test
🤝 Contribution
Les contributions sont les bienvenues ! Merci de :
- Fork le projet
- Créer une branche pour votre fonctionnalité
- Commiter vos changements
- Pousser vers la branche
- Créer une Pull Request
📄 Licence
Ce package est sous licence MIT. Voir le fichier LICENSE pour plus de détails.
🙏 Remerciements
📞 Support
Créé avec ❤️ par Sultan Thomas