Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Admin Users Laravel Package

snoeren-development/laravel-admin-users

View on GitHub
Deep Wiki
Context7

Laravel Admin Users

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony