Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Macroable Trait to LocationManager for Extensibility #174

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

a1383n
Copy link
Contributor

@a1383n a1383n commented Jun 12, 2024

Overview

This pull request improves the LocationManager class by adding the Macroable trait. This enhancement allows developers to create custom macros, expanding what LocationManager can do without changing its main code.

Changes Made

Added the Illuminate\Support\Traits\Macroable trait to the LocationManager class.

Benefits

  • Flexibility: Developers can now customize LocationManager to better fit specific project needs using custom macros.
  • Modularity: Macros help organize code by encapsulating custom functions within LocationManager.
  • Maintainability: This approach supports adding new features without modifying the core library code.

Example Usage

For instance, a practical macro that retrieves a full address based on an IP address:

use Stevebauman\Location\Facades\Location;

Location::macro('getFullAddress', function ($ipAddress) {
    $location = Location::get($ipAddress);

    if ($location) {
        return "{$location->cityName}, {$location->regionName}, {$location->countryName}";
    }

    return 'Location not found';
});

// Example of usage
$fullAddress = Location::getFullAddress('8.8.8.8');
echo $fullAddress;  // Outputs something like: "Ashburn, Virginia, United States"

This example demonstrates how developers can extend LocationManager to fetch and format detailed location information based on an IP address.

@a1383n a1383n changed the title Add Macroable Trait to LocationManager for Extensibility Add Macroable Trait to LocationManager for Extensibility Jun 12, 2024
@stevebauman
Copy link
Owner

Thanks @a1383n!

@stevebauman stevebauman merged commit 9fe2080 into stevebauman:master Jun 13, 2024
1 of 8 checks passed
@a1383n a1383n deleted the feat/add_macroable_trait branch June 13, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants