定制 avcodewizard/block-by-country 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

avcodewizard/block-by-country

最新稳定版本:1.0.1

Composer 安装命令:

composer require avcodewizard/block-by-country

包简介

README 文档

README

Laravel Logo

Block By Country Laravel Package

A simple Laravel package to block your application access by country.

Features

  • Block access to your Laravel app based on country.
  • Using ipinfo.io to detect the user's country by their IP address.
  • Easy configuration of blocked countries.
  • Middleware-based approach, so it’s flexible and extendable.

Installation

Step 1: Install the package via Composer

You can install this package via Composer by running the following command in your Laravel project:

composer require avcodewizard/block-by-country

Step 2: Publish the configuration file

The package includes a configuration file where you can define which countries to block. The configuration file will be automatically published to your Laravel app. However, if you need to update or publish it manually, you can run:

php artisan vendor:publish --provider="Avcodewizard\BlockByCountry\BlockByCountryServiceProvider" --tag="config"

Step 3: Update config/blockbycountry.php

In the configuration file config/blockbycountry.php, you can specify the ISO country codes that you want to block.

return [
    'blocked_countries' => ['CN', 'RU', 'IR'], // Add country codes to block here.
];

Step 4: Add Middleware to Routes

To block specific routes based on the user's country, simply apply the middleware block.country to any route or route group.

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware('block.country');

OR

Route::group(['middleware' => 'block.country'], function () {

    Route::get('/dashboard', function () {
        return view('dashboard');
    });

    // put all your routes inside this group ...
});

Requirements

  • PHP 7.4 or higher
  • Laravel 8.x or higher

统计信息

  • 总下载量: 44
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-24