定制 handersonsilva/laravel-access 二次开发

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

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

handersonsilva/laravel-access

Composer 安装命令:

composer create-project handersonsilva/laravel-access

包简介

A package to manage access to your Laravel application per environment

README 文档

README

Total Downloads Latest Stable Version License

About Laravel Access

Laravel Access is a package that provides a simple way to manage access control per environments in Laravel applications.

Requirements

  • PHP >= 8.3
  • Laravel >= 10.0

Services required

  • Email Server (any driver)
  • Cache (any driver)

Installation

Add the package to your project

composer require handersonsilva/laravel-access

Publish the package in your project

php artisan vendor:publish --provider="SecurityTools\LaravelAccess\Providers\AccessServiceProvider"

Middleware

Add the following code to the app/Http/Kernel.php file on the global middleware

protected $middleware = [
        \SecurityTools\LaravelAccess\Middleware\AccessMiddleware::class,
        ...
];

Laravel 11+ (bootstrap/app.php)

If your app uses the new Laravel bootstrap middleware configuration, register AccessMiddleware in bootstrap/app.php:

->withMiddleware(function (Middleware $middleware): void {
    $middleware->web(append: [
        \SecurityTools\LaravelAccess\Middleware\AccessMiddleware::class,
    ]);
})

Laravel + React (Inertia) stack

If your project uses Laravel with React and Inertia, requests sent with X-Inertia should use a full-page redirect when access is blocked.
Add a middleware like HandleInertiaAccessRedirect and register it before AccessMiddleware.

1) Create the middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
use Inertia\Inertia;
use SecurityTools\LaravelAccess\Services\AccessService;
use Symfony\Component\HttpFoundation\Response;

class HandleInertiaAccessRedirect
{
    public function __construct(private readonly AccessService $accessService)
    {
    }

    /**
     * Ensure Inertia requests trigger a full-page redirect when access is blocked.
     *
     * @param  Closure(Request): Response  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if ($request->header('X-Inertia') && $this->accessService->isBlocked($request)) {
            return Inertia::location(URL::route(AccessService::DEFAULT_ROUTE_ACCESS));
        }

        return $next($request);
    }
}

2) Register in bootstrap/app.php

->withMiddleware(function (Middleware $middleware): void {
    $middleware->web(append: [
        \App\Http\Middleware\HandleInertiaAccessRedirect::class,
        \SecurityTools\LaravelAccess\Middleware\AccessMiddleware::class,
    ]);
})

3) Cookie encryption compatibility

This package manages the access cookie _ac_ck directly.
In the host app, exclude this cookie from Laravel cookie encryption:

$middleware->encryptCookies(except: [
    '_ac_ck',
]);

Run the initial configuration

php artisan access:install

Configuration

Add environments in the .env file

# Access  
ACCESS_ENABLE=true # Enable access
ACCESS_SECRET=your_secret_key # Generate any secret key 

Block access to the application per environment

Add the following code to the config/access.php file to block access to the application in the environments you want.

'block_env' => ['local'], # Environments to block access to the application ex: ['local', 'staging', 'production']

Block access to the application per route prefix

'block_prefixes' => ['/admin'], # Prefixes to block access to the application ex: ['/admin', '/private']

Define the default route to redirect the user after validation

'redirect_prefix' => '/admin',# Default route to redirect the user after validation default: '/'

See the complete configuration in the config/access.php file

Auto Login

To enable auto login, add the following code to the .env file

# Access  
ACCESS_AUTO_LOGIN=true # Enable auto login
ACCESS_GUARD=web # Guard to be used for authentication

When auto login is enabled, the user will be automatically authenticated to the application without the need to enter the login and password.

Security Vulnerabilities

If you discover a security vulnerability within Laravel Access, please send an e-mail to Handerson Silva via handersonsylva@gmail.com. All security vulnerabilities will be promptly addressed.

License

The Laravel Access framework is open-sourced software licensed under the MIT license.

handersonsilva/laravel-access 适用场景与选型建议

handersonsilva/laravel-access 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 handersonsilva/laravel-access 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 handersonsilva/laravel-access 我们能提供哪些服务?
定制开发 / 二次开发

基于 handersonsilva/laravel-access 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-19