osenco/filament-google-map-location-picker

There is no license information available for the latest version (0.0.1) of this package.

Google map location picker for filament

0.0.1 2024-12-15 16:44 UTC

This package is auto-updated.

Last update: 2024-12-15 16:59:37 UTC


README

forked from https://packagist.org/packages/sadiq/filament-gmap-location-picker, updated to work with Filament >=3.0

Installation

You can install the package via composer:

 composer require osenco/filament-google-map-location-picker

Optionally, you can publish the config using

php artisan vendor:publish --tag="filament-google-map-location-picker-config"

Config

filament-google-map-location-picker.php

<?php

return [
    'google_map_key' => "",
];

make migration location column to database

add location column to database

...
        Schema::table('table_name', function (Blueprint $table) {
            $table->json("location")->nullable();
        });
...
use Yemenpoint\FilamentGoogleMapLocationPicker\Forms\Components\LocationPicker;

...

    public static function form(Form $form): Form
    {
        return $form->schema([
              LocationPicker::make('location')
                  ->default(json_encode(["lat" => 15.356893920277, "lng" => 44.173358011179]))//set default location
                  ->defaultZoom(12)// set zoom 
                  ->setLocationCenter([
                      'lat' => 15.356893920277,
                      'lng' => 44.173358011179,
                  ]) //set location center 
                  ->required()
                  ->columnSpan(2),
        ]);
    }
...

Model

add column name to fillable

...

    protected $fillable = [
        "location"
    ];
...

if u have separate column for lat and lng add this Mutator

...
    function setLocationAttribute($value)
    {
        //replace lat_column_name and lng_column_name with your column names
        $this->attributes['location'] = $value;
        $_location = @json_decode($value,true);
        $this->attributes['lat_column_name'] = data_get($_location,"lat");
        $this->attributes['lng_column_name'] = data_get($_location,"lng");
    }

...

Credits

License

The MIT License (MIT). Please see License File for more information.