Use the make:filament-google-maps-widget command to generate a new map widget class. This command automates the creation of the widget class and its corresponding Blade view, and it attempts to automatically wire up the model's latitude, longitude, and location attributes.
Prerequisite:
Your model must have the latitude and longitude attributes defined. If you haven't done this yet, run the fgm:model-code command and paste the resulting code into your model before running this command.
Usage:
php artisan make:filament-google-maps-widget {name?} {model?} {--R|resource=} {--M|map} {--T|table} {--F|force}
Arguments:
name: The name of the widget class (e.g., DealershipMap).model: The model the widget will use (e.g., Location or Maps/Dealership).
Options:
--resource=: (Optional) The resource where the widget should be placed (e.g., LocationResource). If provided, the widget is created within the resource's directory structure.--map: Specifies a simple map widget type.--table: Specifies a map widget with an integrated table.--force: Overwrites existing files if they already exist.
Post-Creation Steps:
If used within a Resource:
- Register the widget in your resource class using
getWidgets(). - Register the widget in your resource page (e.g.,
ListRecords, ViewRecord, or ManageRecords) by adding it to either getHeaderWidgets() or getFooterWidgets().
If used as a standalone widget (not in a resource):
- Move the generated file to your Livewire widgets directory (e.g.,
app/Http/Livewire/Widgets/). - Invoke it in a Blade template using:
@livewire('widgets.your_widget_name_in_snake_case').
php artisan make:filament-google-maps-widget DealershipMap Location --resource=LocationResource