• Reading time ~ 1 min
  • 09.07.2022

Laravel Ban is a package that simplifies blocking and banning Eloquent models. Using this package, you can make a model "bannable" in minutes.

The use case for this package goes beyond a User model; you can add the concept of a ban to any Eloquent model. The main features of this package include:

  • Model can have many bans.
  • Removed bans kept in history as soft-deleted records.
  • Most parts of the logic is handled by the BanService.
  • Has middleware to prevent banned user route access.
  • Use case is not limited to User model, any Eloquent model could be banned.
  • Events firing on models ban and unban.
  • Designed to work with Laravel Eloquent models.
  • Has Laravel Nova support.
  • Using contracts to keep high customization capabilities.
  • Using traits to get functionality out of the box.

The package has a nice API that makes banning the model simple:

$user->ban();

$user->ban([
    'comment' => 'Enjoy your ban!',
]);
// A ban that has a ban expiry date
$user->ban([
    'expired_at' => '+1 month',
]);
// Remove a ban
$user->unban();

// Boolean checks
$user->isBanned();
$user->isNotBanned();
$ban->isTemporary();

The package also provides nice conveniences like middleware, events, scopes, and auto-applying scopes to a model.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297