DEV Community

Cover image for Laravel Mapbox, easily integrate Mapbox inside your Laravel app
Koussay
Koussay

Posted on

Laravel Mapbox, easily integrate Mapbox inside your Laravel app

I have just released Laravel Mapbox, a Laravel package that allows you to add Mapbox to your views easily, with highly flexibility.
It requires Laravel 8 and PHP 8.0 and up.

Before installing the package, create a Mapbox account to get your token.

Installation

To install the package, all you have to do is run this command

composer require koossaayy/laravel-mapbox 
Enter fullscreen mode Exit fullscreen mode

After the installation, add this key to the .env file

MAPBOX_TOKEN={your mapbox token here}
Enter fullscreen mode Exit fullscreen mode

And lastly publish the config file using this command :

php artisan vendor:publish --tag="mapbox-config"
Enter fullscreen mode Exit fullscreen mode

Also don't forget to add CSS and JS files of Mapbox

<link href='https://api.mapbox.com/mapbox-gl-js/v2.6.0/mapbox-gl.css' rel='stylesheet' />
<script src='https://api.mapbox.com/mapbox-gl-js/v2.6.0/mapbox-gl.js'></script>
Enter fullscreen mode Exit fullscreen mode

And that's It you're good to go

Usage

To show a map on a page, all you have to do is use :

<x-mapbox id="map" />
Enter fullscreen mode Exit fullscreen mode

The package comes with a lot with other options, like markers, popups, interactivity, and a lot.
You may check them here

If you like the package, give it a star, and everyone is more than welcome to contribute ♥

Discussion (0)