├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src └── Actions ├── Ban.php └── Unban.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `cybercog/laravel-nova-ban` will be documented in this file. 4 | 5 | ## [Unreleased] 6 | 7 | ## [2.0.0] - 2022-08-13 8 | 9 | ### Added 10 | 11 | - ([#14]) Added Laravel Nova 4 support 12 | 13 | ## [1.2.0] - 2021-01-01 14 | 15 | ### Added 16 | 17 | - ([#11]) Added PHP 8.x support 18 | 19 | ## [1.1.1] - 2020-03-11 20 | 21 | ### Fixed 22 | 23 | - ([#9]) Removed unused `symfony/process` dependency 24 | 25 | ## [1.1.0] - 2019-02-26 26 | 27 | ### Added 28 | 29 | - Laravel Ban v4 support 30 | 31 | ## 1.1.0 - 2018-09-23 32 | 33 | - Initial release 34 | 35 | [Unreleased]: https://github.com/cybercog/laravel-nova-ban/compare/2.0.0...master 36 | [2.0.0]: https://github.com/cybercog/laravel-nova-ban/compare/1.2.0...2.0.0 37 | [1.2.0]: https://github.com/cybercog/laravel-nova-ban/compare/1.1.1...1.2.0 38 | [1.1.1]: https://github.com/cybercog/laravel-nova-ban/compare/1.1.0...1.1.1 39 | [1.1.0]: https://github.com/cybercog/laravel-nova-ban/compare/1.0.0...1.1.0 40 | 41 | [#14]: https://github.com/cybercog/laravel-nova-ban/pull/14 42 | [#11]: https://github.com/cybercog/laravel-nova-ban/pull/11 43 | [#9]: https://github.com/cybercog/laravel-nova-ban/pull/9 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020, Anton Komarev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Nova Ban 2 | 3 | ![cog-laravel-nova-ban](https://user-images.githubusercontent.com/1849174/44558292-ffc0a080-a74b-11e8-8699-a79de865910d.png) 4 | 5 |

6 | Releases 7 | StyleCI 8 | License 9 |

10 | 11 | ## Introduction 12 | 13 | Behind the scenes [cybercog/laravel-ban](https://github.com/cybercog/laravel-ban) is used. 14 | 15 | ![laravel-nova-ban-preview](https://user-images.githubusercontent.com/1849174/44547881-1b648080-a725-11e8-9472-bad1486c06f0.png) 16 | 17 | ## Contents 18 | 19 | - [Installation](#installation) 20 | - [Usage](#usage) 21 | - [Prepare bannable model](#prepare-bannable-model) 22 | - [Prepare bannable model database table](#prepare-bannable-model-database-table) 23 | - [Register Ban Actions in Nova Resource](#register-ban-actions-in-nova-resource) 24 | - [Contributing](#contributing) 25 | - [Testing](#testing) 26 | - [Security](#security) 27 | - [Contributors](#contributors) 28 | - [Alternatives](#alternatives) 29 | - [License](#license) 30 | - [About CyberCog](#about-cybercog) 31 | 32 | ## Installation 33 | 34 | Pull in the package through Composer. 35 | 36 | ```shell script 37 | composer require cybercog/laravel-nova-ban 38 | ``` 39 | 40 | ## Usage 41 | 42 | ### Prepare bannable model 43 | 44 | ```php 45 | use Cog\Contracts\Ban\Bannable as BannableContract; 46 | use Cog\Laravel\Ban\Traits\Bannable; 47 | use Illuminate\Foundation\Auth\User as Authenticatable; 48 | 49 | class User extends Authenticatable implements BannableContract 50 | { 51 | use Bannable; 52 | } 53 | ``` 54 | 55 | ### Prepare bannable model database table 56 | 57 | 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. 58 | 59 | #### Create a new migration file 60 | 61 | ```shell script 62 | php artisan make:migration add_banned_at_column_to_users_table 63 | ``` 64 | 65 | Then insert the following code into migration file: 66 | 67 | ```php 68 | timestamp('banned_at')->nullable(); 80 | }); 81 | } 82 | 83 | public function down(): void 84 | { 85 | Schema::table('users', function (Blueprint $table) { 86 | $table->dropColumn('banned_at'); 87 | }); 88 | } 89 | } 90 | ``` 91 | 92 | Apply new migration. 93 | 94 | ### Register Ban Actions in Nova Resource 95 | 96 | Register `Ban` and `Unban` actions inside your `Bannable` Model's Resource. 97 | 98 | ```php 99 | public function actions(Request $request) 100 | { 101 | return [ 102 | new \Cog\Laravel\Nova\Ban\Actions\Ban(), 103 | new \Cog\Laravel\Nova\Ban\Actions\Unban(), 104 | ]; 105 | } 106 | ``` 107 | 108 | ## Contributing 109 | 110 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 111 | 112 | ## Testing 113 | 114 | Run the tests with: 115 | 116 | ```shell script 117 | vendor/bin/phpunit 118 | ``` 119 | 120 | ## Security 121 | 122 | If you discover any security related issues, please email open@cybercog.su instead of using the issue tracker. 123 | 124 | ## Contributors 125 | 126 | | ![@antonkomarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev
| ![@ sergiy-petrov ](https://avatars.githubusercontent.com/u/8986207?s=110)
Sergiy Petrov
| ![@mvdnbrk](https://avatars.githubusercontent.com/u/802681?s=110)
Mark van den Broek
| ![@tooshay](https://avatars.githubusercontent.com/u/703589?s=110)
Roy Shay
| 127 | | :---: | :---: | :---: | :---: | 128 | 129 | [Laravel Nova Ban contributors list](../../contributors) 130 | 131 | ## Alternatives 132 | 133 | *Feel free to add more alternatives as Pull Request.* 134 | 135 | ## License 136 | 137 | - `Laravel Nova Ban` package is open-sourced software licensed under the [MIT License](LICENSE) by [Anton Komarev]. 138 | - `Fat Boss In Jail` image licensed under [Creative Commons 3.0](https://creativecommons.org/licenses/by/3.0/us/) by Gan Khoon Lay. 139 | 140 | ## About CyberCog 141 | 142 | [CyberCog] is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion. 143 | 144 | - [Follow us on Twitter](https://twitter.com/cybercog) 145 | 146 | CyberCog 147 | 148 | [Anton Komarev]: https://komarev.com 149 | [CyberCog]: https://cybercog.su 150 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cybercog/laravel-nova-ban", 3 | "description": "A Laravel Nova banning functionality for your application.", 4 | "type": "library", 5 | "license": "MIT", 6 | "keywords": [ 7 | "cog", 8 | "laravel", 9 | "nova", 10 | "eloquent", 11 | "trait", 12 | "justice", 13 | "user", 14 | "ban", 15 | "block", 16 | "restrict", 17 | "forbid", 18 | "arrest", 19 | "jail" 20 | ], 21 | "authors": [ 22 | { 23 | "name": "Anton Komarev", 24 | "email": "anton@komarev.com", 25 | "homepage": "https://komarev.com", 26 | "role": "Developer" 27 | } 28 | ], 29 | "homepage": "https://komarev.com/sources/laravel-nova-ban", 30 | "support": { 31 | "email": "open@cybercog.su", 32 | "issues": "https://github.com/cybercog/laravel-nova-ban/issues", 33 | "wiki": "https://github.com/cybercog/laravel-nova-ban/wiki", 34 | "source": "https://github.com/cybercog/laravel-nova-ban", 35 | "docs": "https://github.com/cybercog/laravel-nova-ban/wiki" 36 | }, 37 | "require": { 38 | "php": "^7.1.3|^8.0", 39 | "laravel/nova": "*", 40 | "cybercog/laravel-ban": "^3.0|^4.0" 41 | }, 42 | "require-dev": { 43 | }, 44 | "autoload": { 45 | "psr-4": { 46 | "Cog\\Laravel\\Nova\\Ban\\": "src/" 47 | } 48 | }, 49 | "autoload-dev": { 50 | "psr-4": { 51 | "Cog\\Tests\\Laravel\\Nova\\Ban\\": "tests/" 52 | } 53 | }, 54 | "config": { 55 | "sort-packages": true 56 | }, 57 | "minimum-stability": "dev", 58 | "prefer-stable": true 59 | } 60 | -------------------------------------------------------------------------------- /src/Actions/Ban.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Cog\Laravel\Nova\Ban\Actions; 15 | 16 | use Illuminate\Bus\Queueable; 17 | use Illuminate\Queue\InteractsWithQueue; 18 | use Illuminate\Queue\SerializesModels; 19 | use Illuminate\Support\Collection; 20 | use Laravel\Nova\Actions\Action; 21 | use Laravel\Nova\Fields\ActionFields; 22 | use Laravel\Nova\Fields\DateTime; 23 | use Laravel\Nova\Fields\Text; 24 | use Laravel\Nova\Http\Requests\NovaRequest; 25 | 26 | class Ban extends Action 27 | { 28 | use InteractsWithQueue; 29 | use Queueable; 30 | use SerializesModels; 31 | 32 | /** 33 | * Perform the action on the given models. 34 | * 35 | * @param ActionFields $fields 36 | * @param Collection $models 37 | * @return mixed 38 | */ 39 | public function handle(ActionFields $fields, Collection $models) 40 | { 41 | foreach ($models as $model) { 42 | $model->ban([ 43 | 'comment' => $fields->get('comment'), 44 | 'expired_at' => $fields->get('expired_at'), 45 | ]); 46 | } 47 | 48 | return Action::message('Models were banned!'); 49 | } 50 | 51 | /** 52 | * Get the fields available on the action. 53 | * 54 | * @return array 55 | */ 56 | public function fields(NovaRequest $request) 57 | { 58 | return [ 59 | Text::make('Comment', 'comment'), 60 | 61 | DateTime::make('Expires At', 'expired_at'), 62 | ]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Actions/Unban.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Cog\Laravel\Nova\Ban\Actions; 15 | 16 | use Illuminate\Bus\Queueable; 17 | use Illuminate\Queue\InteractsWithQueue; 18 | use Illuminate\Queue\SerializesModels; 19 | use Illuminate\Support\Collection; 20 | use Laravel\Nova\Actions\Action; 21 | use Laravel\Nova\Fields\ActionFields; 22 | use Laravel\Nova\Http\Requests\NovaRequest; 23 | 24 | class Unban extends Action 25 | { 26 | use InteractsWithQueue; 27 | use Queueable; 28 | use SerializesModels; 29 | 30 | /** 31 | * Perform the action on the given models. 32 | * 33 | * @param ActionFields $fields 34 | * @param Collection $models 35 | * @return mixed 36 | */ 37 | public function handle(ActionFields $fields, Collection $models) 38 | { 39 | foreach ($models as $model) { 40 | $model->unban(); 41 | } 42 | 43 | return Action::message('Models were unbanned!'); 44 | } 45 | 46 | /** 47 | * Get the fields available on the action. 48 | * 49 | * @return array 50 | */ 51 | public function fields(NovaRequest $request) 52 | { 53 | return []; 54 | } 55 | } 56 | --------------------------------------------------------------------------------