Download the PHP package hkp22/laravel-bannable without Composer
On this page you can find all versions of the php package hkp22/laravel-bannable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-bannable
Laravel Bannable
Laravel bannable package for blocking and banning Eloquent models. Using this package any model can be made bannable such as Organizations, Teams, Groups, and others.
Installation
Download package into the project using Composer.
Registering package
Laravel 5.5 (or higher) uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
For Laravel 5.4 or earlier releases version include the service provider within app/config/app.php:
Prepare Migration
Now need to add nullable banned_at timestamp column to model. So, create a new migration file.
Add $table->timestamp('banned_at')->nullable(); in this new migration file as in below example.
Now run migration.
Prepare bannable model
Use Bannable trait in the Model as in below example.
Available methods
Ban model entity.
Ban model entity with reason comment
Ban model entity with expire time
Here expired_at attribute could be \Carbon\Carbon instance or any time string which could be parsed by \Carbon\Carbon::parse($string) method:
or
or
Remove ban model
On unban all related ban models are soft deletes.
Check if entity is banned
Check if entity is not banned
Delete expired bans manually
Scopes
Get all models which are not banned
Get banned and not banned models
Get only banned models
Disable scope that hides banned models entity by default
By default all banned models will be hidden. To disable query scopes all the time you can define disableBannedAtScope method in bannable model.
Events
On model entity ban \Qirolab\Laravel\Bannable\Events\ModelWasBanned event is fired.
On model entity unban \Qirolab\Laravel\Bannable\Events\ModelWasUnbanned event is fired.
Middleware
To prevent banned users to go to protected routes Qirolab\Laravel\Bannable\Middleware\ForbidBannedUser middleware is created.
Register it in $routeMiddleware array of app/Http/Kernel.php file:
protected $routeMiddleware = [ 'isBannedUser' => \Qirolab\Laravel\Bannable\Middleware\ForbidBannedUser::class, ]
All versions of laravel-bannable with dependencies
illuminate/database Version 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0
illuminate/events Version 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0
illuminate/support Version 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0