Laravel Nova Ban simplify blocking and banning Eloquent models.

Overview

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

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

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

    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
    opened by tooshay 1
  • Update to Laravel 7

    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.

    opened by mvdnbrk 1
  • Missing Class 'App\User\Ban' Not Found

    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

    opened by JoshReading 1
  • example on using on a user resource?

    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

    question 
    opened by codeitlikemiley 1
  • ModelWasBanned doesn't trigger in Nova.

    ModelWasBanned doesn't trigger in Nova.

    (Continuing the thread from https://github.com/cybercog/laravel-ban/issues/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.)

    opened by rickmacgillis 0
Releases(2.0.0)
Owner
cybercog
CyberCog is a Social Unity of enthusiasts. Developing best solutions in the field of product & software development is our passion.
cybercog
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Renoki Co. 720 Jan 3, 2023
This Laravel Nova tool lets you run artisan and bash commands directly from Nova 4 or higher.

Laravel Nova tool for running Artisan & Shell commands. This Nova tool lets you run artisan and bash commands directly from nova. This is an extended

Artem Stepanenko 17 Dec 15, 2022
This Laravel Nova settings tool based on env, using nativ nova fields and resources

Nova Settings Description This Laravel Nova settings tool based on env, using nativ nova fields and resources Features Using native Nova resources Ful

Artem Stepanenko 21 Dec 28, 2022
This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields.

Nova Trumbowyg Field This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields. Requirements php: >=8.0 laravel/nova: ^4.0 Installa

outl1ne 3 Sep 25, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
A non-blocking stream abstraction for PHP based on Amp.

amphp/byte-stream is a stream abstraction to make working with non-blocking I/O simple. Installation This package can be installed as a Composer depen

Amp 317 Dec 22, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Jan 7, 2023
cybercog 996 Dec 28, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Dec 30, 2022
🕵️ Inspect Laravel Eloquent models to collect properties, relationships and more.

??️ Eloquent Inspector Inspect Laravel Eloquent models to collect properties, relationships and more. Install Via Composer composer require cerbero/el

Andrea Marco Sartori 111 Nov 4, 2022
Package with small support traits and classes for the Laravel Eloquent models

Contains a set of traits for the eloquent model. In future can contain more set of classes/traits for the eloquent database.

Martin Kluska 3 Feb 10, 2022
A Laravel package to simplify using DPO Payment API in your application.

DPO (Direct Pay Online) Laravel Package The best DPO Laravel package, simple Ever This is the package that will help you add DPO Payment API to your L

Zepson Technologies 5 Nov 17, 2022
Laravel charts is a package to simplify the use of charts.

Laravel Charts Laravel charts is a package to simplify the use of charts. Features Autoregister your charts Customize routing, middleware and prefix t

Datalogix 2 Aug 5, 2022
Use auto generated UUID slugs to identify and retrieve your Eloquent models.

Laravel Eloquent UUID slug Summary About Features Requirements Installation Examples Compatibility table Alternatives Tests About By default, when get

Khalyomede 25 Dec 14, 2022
Record created by, updated by and deleted by on Eloquent models automatically.

quarks/laravel-auditors Record created by, updated by and deleted by (if SoftDeletes added) on Eloquent models automatically. Installation composer re

Quarks 3 Jun 13, 2022
Observe (and react to) attribute changes made on Eloquent models.

Laravel Attribute Observer Requirements PHP: 7.4+ Laravel: 7+ Installation You can install the package via composer: composer require alexstewartja/la

Alex Stewart 55 Jan 4, 2023
Easy creation of slugs for your Eloquent models in Laravel

Eloquent-Sluggable Easy creation of slugs for your Eloquent models in Laravel. NOTE: These instructions are for the latest version of Laravel. If you

Colin Viebrock 3.6k Dec 30, 2022
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 955 Dec 25, 2022
Tag support for Laravel Eloquent models - Taggable Trait

Laravel Taggable Trait This package is not meant to handle javascript or html in any way. This package handles database storage and read/writes only.

Rob 859 Dec 11, 2022