snoeren-development/laravel-admin-users 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

snoeren-development/laravel-admin-users

最新稳定版本:v1.10.1

Composer 安装命令:

composer require snoeren-development/laravel-admin-users

包简介

Define and check for admin users in your application!

README 文档

README

Latest version on Packagist Software License Build status Downloads

This small package adds a configuration and user model trait to define administrators within your application.

Installation

Install the package using Composer:

composer require snoeren-development/laravel-admin-users

Requirements

This package requires at least PHP 8.2 and Laravel 10.

Usage

Add the SnoerenDevelopment\AdminUsers\Adminable trait to your user model and define administrator users using the ADMINS= environment variable. The variable should contain a comma separated list of email addresses of your application administrators.

Using the middleware

This package comes with middleware. This middleware checks if the user is an administrator. If not, the middleware throws a 401 unauthorised exception.

Add the middleware to your $routeMiddleware list in the HTTP kernel to use.

// Kernel.php
'admin' => \SnoerenDevelopment\AdminUsers\AdminMiddleware::class,

Grant administrators all permissions

// AuthServiceProvider.php

use Illuminate\Support\Facades\Gate;

public function boot()
{
    $this->registerPolicies();

    Gate::before(function ($user, $ability) {
        if ($user->isAdmin()) {
            return true;
        }
    });
}

Using the gate via Blade

{{-- Using the gate via the can-statement. --}}
@can('admin')
    The current user is an admin!
@else
    The current user is not an admin!
@endcan

{{-- Using the custom if-statement --}}
@admin
    The current user is an admin!
@else
    The current user is not an admin!
@endadmin

Publishing the configuration file

You can publish the configuration file to your project using php artisan vendor:publish. Then select the admin package.

Using the MySQL driver

Publish and run the migration or manually add the is_admin column to your users table. Set the driver to mysql in your .env file using ADMINS_DRIVER=mysql.

Testing

composer test

Credits

License

The MIT license. See LICENSE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-17