cybercog/laravel-nova-ban

A Laravel Nova banning functionality for your application.
207,764 40
Install
composer require cybercog/laravel-nova-ban
Latest Version:2.0.0
PHP:^7.1.3|^8.0
License:MIT
Last Updated:Aug 26, 2022
Links: GitHub  ·  Packagist
Maintainer: antonkomarev

Laravel Nova Ban

cog-laravel-nova-ban

Introduction

Behind the scenes cybercog/laravel-ban is used.

laravel-nova-ban-preview

Contents

Installation

Pull in the package through Composer.

composer require cybercog/laravel-nova-ban

Usage

Prepare bannable model

use Cog\Contracts\Ban\Bannable as BannableContract;
use Cog\Laravel\Ban\Traits\Bannable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements BannableContract
{
    use Bannable;
}

Prepare bannable model database table

Bannable model must have nullable timestamp column named banned_at. This value used as flag and simplify checks if user was banned. If you are trying to make default Laravel User model to be bannable you can use example below.

Create a new migration file

php artisan make:migration add_banned_at_column_to_users_table

Then insert the following code into migration file:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddBannedAtColumnToUsersTable extends Migration
{
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->timestamp('banned_at')->nullable();
        });
    }
    
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('banned_at');
        });
    }
}

Apply new migration.

Register Ban Actions in Nova Resource

Register Ban and Unban actions inside your Bannable Model's Resource.

public function actions(Request $request)
{
    return [
        new \Cog\Laravel\Nova\Ban\Actions\Ban(),
        new \Cog\Laravel\Nova\Ban\Actions\Unban(),
    ];
}

Contributing

Please see CONTRIBUTING for details.

Testing

Run the tests with:

vendor/bin/phpunit

Security

If you discover any security related issues, please email open@cybercog.su instead of using the issue tracker.

Contributors

@antonkomarevAnton Komarev @ sergiy-petrov Sergiy Petrov @mvdnbrkMark van den Broek @tooshayRoy Shay

Laravel Nova Ban contributors list

Alternatives

Feel free to add more alternatives as Pull Request.

License

About CyberCog

CyberCog is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion.

Related Packages

cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

713,377 1,127
cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

341,706 1,203
racashmoney/laravel-blockable

Trait for Laravel Eloquent models to allow easy implementation of a 'block' or '...

25 4
koodoo/laravel-trait-uuid

A Laravel Eloquent Model trait for adding a UUID to Eloquent Models

16,562 0
ironshark/laravel-extendable

Traits for Laravel to add and manage custom Eloquent model fields.

11,037 24