trinityrank / geo-location

GeoLocation - 在所选国家显示或隐藏操作员

v1.1 2024-04-22 12:56 UTC

This package is auto-updated.

Last update: 2024-09-22 13:59:19 UTC


README

Latest Version on Packagist Total Downloads

通过从列表中选择国家来选择显示或隐藏操作员。

安装

步骤 1: 安装包

要开始使用 Laravel Geo Location,请使用 Composer 命令将包添加到 composer.json 项目依赖中

    composer require trinityrank/geo-location

步骤 2: 迁移

  • 您需要从包中发布迁移
    php artisan vendor:publish --provider="Trinityrank\GeoLocation\GeoLocationServiceProvider" --tag="geolocation-migration"
  • 然后您需要为所有租户运行迁移
    php artisan tenant:artisan "migrate"
  • 或仅针对一个特定租户
    php artisan tenant:artisan "migrate" --tenant=[--TENANT-ID--]

步骤 3: 操作员模型数据库

将此字段添加到操作员模型中的 '$fillable' 内部

    public $fillable = [
        ...
        'geolocation_option',
        'geolocation_countries',
    ];

步骤 4: 添加字段

  • 将字段添加到您的(操作员)资源中的 "fields" 方法
    use Trinityrank\GeoLocation\GeoLocationPanel;
    
    ...
    
    GeoLocationPanel::make()
  • 或如果您使用条件字段,只需将其添加到 "fields" 方法中
    $this->getGeoLocationPanel('GeoLocation Page Settings', 'geolocation')

步骤 5: 如果您使用条件字段

将其添加到租户配置中

    'conditional_fields' => [
        ...

        'operater' => [
            'geolocation' => [
                'visible' => true
            ]
        ]

        ...
    ]

前端部分

  • 无令牌
    use Trinityrank\GeoLocation\GeoLocationOperater;

    ...

    $operaters = GeoLocationOperater::list($operaters_array);
  • 带有令牌

在 .ENV 文件中添加新变量

    GEOLOCATION_API_TOKEN=[--Replace-this-with-website-token--]

您可以通过 'config/main.php' 文件连接

    'geolocation_api_token' => env('GEOLOCATION_API_TOKEN', null),

然后我们可以使用我们的 Geo Location

    use Trinityrank\GeoLocation\GeoLocationOperater;

    ...

    $operaters = GeoLocationOperater::list($operaters_array, $api_token = [optional]);