Giter Club home page Giter Club logo

laravel-nova-ban's Introduction

Laravel Nova Ban

cog-laravel-nova-ban

Releases StyleCI License

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 [email protected] instead of using the issue tracker.

Contributors

@antonkomarev
Anton Komarev
@ sergiy-petrov
Sergiy Petrov
@mvdnbrk
Mark van den Broek
@tooshay
Roy 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.

CyberCog

laravel-nova-ban's People

Contributors

antonkomarev avatar jeffersonsimaogoncalves avatar mvdnbrk avatar tooshay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-nova-ban's Issues

Missing Class 'App\User\Ban' Not Found

If you manage to get this error message on load after following the instructions add

use Cog\Laravel\Nova\Ban\Actions\Ban;
use Cog\Laravel\Nova\Ban\Actions\Unban;

Into your Bannable Nova resource

Unban::fields() and Ban::fields() base class compatibility problem

After going through the installation process and reloading the Users management page in Nova, I ran into this:

Declaration of Cog\Laravel\Nova\Ban\Actions\Ban::fields() must be compatible with Laravel\Nova\Actions\Action::fields(Laravel\Nova\Http\Requests\NovaRequest $request)

It looks like both Ban and Unban need their fields() methods updated to include the missing NovaRequest object.

We're running:

  • PHP 8.1
  • Laravel 9.1.3
  • Nova 4.12
  • Ban 4.7
  • Nova Ban 1.2

ModelWasBanned doesn't trigger in Nova.

(Continuing the thread from cybercog/laravel-ban#44)

I can unban people and the event triggers in Nova, but when I ban them, the user is banned, but no event gets fired. The observer triggers, but when it gets to $bannable->setBannedFlag($ban->created_at)->save(); it stops afterwards. (See: BanObserver.php Line 48)

EDIT:
I found the issue, and it's because the exception that was thrown was caught in my own version of Laravel Nova Ban. I just forgot to alert the Nova user that it didn't work correctly. (I customized mine with logging when I was just getting started with Nova in its pre-1.0 state. After removing the try/catch block and manual logging, it works just fine. Nova logs them correctly now that it has come of age.)

Update to Laravel 7

The requirement of symfony/process: ^4.1 prevents from updating to Laravel v7.

I don't see the need to require symfony/process, can be removed as a required dependency.

example on using on a user resource?

i tried doing something like this

Boolean::make('Banned')->resolveUsing(function ($user) { return $user->banned_at; }) ->exceptOnForms(),
but when i used actions , it is not reactive can u give example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.