承接 snoeren-development/laravel-admin-users 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

snoeren-development/laravel-admin-users

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.3 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.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固