定制 mvd81/laravel-is-admin 二次开发

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

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

mvd81/laravel-is-admin

Composer 安装命令:

composer require mvd81/laravel-is-admin

包简介

Laravel package, simple functionality to set a user as admin without an advanced role system

README 文档

README

Build Status Total Downloads Latest Stable Version License

Introduction

Laravel package to extend your Laravel application with a simple admin permission functionality, with:

  • Migration file to set a user as admin
  • Middleware
  • Blade directive
  • Artisan command to see who is an admin
  • Option to set user with ID 1 as super admin

Installation

  1. composer require mvd81/laravel-is-admin

  2. Run php artisan migrate to create the 'is_admin' column in the users table

  3. Import the trait in the User model

use Mvd81\LaravelIsAdmin\Traits\isAdmin;
  1. Use the trait in the User model
class User extends Authenticatable
{
    use isAdmin;
    ...
  1. Add is_admin to the $fillable array in the User model

How to use

You can set a 'normal' user as admin by setting the database column is_admin to 1 , in database table users.

Or in the code

Make admin

$user = User::find(ID);
$user->makeAdmin(); 

Undo admin

$user = User::find(ID);
$user->undoAdmin(); 

Super admin

It is possible to use user with ID 1 as admin without setting the 'is_admin' column to 1.
First you need to publish the config file.

  • php artisan vendor:publish
  • Choose the option: Provider: Mvd81\LaravelIsAdmin\LaravelIsAdminServiceProvider

Now in config/is_admin.php set 'use_super_admin' to true.

'use_super_admin' => true,

Middleware

There is a IsAdmin middleware to use in your routes.

Example:

Route::get('admin-page')->middleware('IsAdmin'); 

Blade directive

Partial template/layout in your Blade view files only for admins?
You can use this Blade directive

@isAdmin()
    I am an admin
@endisAdmin

Who is an admin?

You can enter an artisan command to see who is an admin.

php artisan user:who-is-admin

Uninstall

  1. composer remove mvd81/laravel-is-admin
  2. Remove the config file config/is_admin.php
  3. Remove the database is_admin column in table users
  4. If you used the blade @isAdmin() directive, remove them
  5. Remove the is_admin middleware from your routes

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固