Kyrch/
laravel-prohibitions
g4t.io

Restrict User Actions with Time-Based Sanctions Using Laravel Prohibitions

17 views 58 stars by Yannick Lyn Fatt

Prohibit your models from execute an action in a way similar to spatie/laravel-permission.

README from Kyrch/laravel-prohibitions Open on GitHub →

Prohibit your models

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Description

Laravel Prohibitions is a Laravel package that allows you to prohibit users from executing specific actions for a determined period of time.

Instead of relying on hard-coded checks or ad-hoc flags, this package introduces a sanction-based system where actions can be explicitly denied through well-defined rules.

The package also provides a Sanction model, which works as a preset of prohibited actions, making it easy to group multiple prohibitions under a single disciplinary rule — such as temporary bans, feature restrictions, or full account suspensions.

Installation

You can install the package via composer:

composer require kyrch/laravel-prohibitions

You can publish the config file with:

php artisan vendor:publish --tag="laravel-prohibitions-config"

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-prohibitions-migrations"

Usage

Setup

Add the HasSanctions trait to your User model:

use Kyrch\Prohibition\Traits\HasSanctions;

class User extends Authenticatable
{
    use HasSanctions;
}

You need to create your sanctions and prohibitions first. For example:

$prohibition = Prohibition::query()->create(['name' => 'update post']);

$sanction = Sanction::query()->create(['name' => 'posts']);

$prohibition->sanctions()->attach($sanction);

How to prohibit

Now you can use methods this packages provides, such as:

# Prohibit the user from updating any posts.
$user->prohibit('update post', now()->addWeek());

# Similar to roles, you can create a kind of "ban preset" that has a group of prohibitions.
$user->applySanction('posts', now()->addWeek());

# Check if user is prohibited from updating any post.
$user->isProhibitedFrom('update post');

It is recommended to use the isProhibitedFrom() method in your Gate::before or the before method in your policy class.

Events

There are two events: ModelProhibitionTriggered and ModelSanctionTriggered. If you don't want them enabled, you can disable it in the published config file.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

More from the ecosystem

durable-workflow/
workflow
g4t.io
9 1,292

Durable Workflow: Long-Running Workflows for Laravel

Embedded durable workflow runtime and orchestration engine for Laravel applications.

durable-workflow/workflow via Laravel News
packstub/
session-replay
g4t.io
14 52

Session Replay for Laravel: Self-Hosted Browser Recordings

Session replay for Laravel: record what a person did in the browser with rrweb, keep the recording on your own disk and database, and watch it behind a gate you define — masked inputs by default, errors, failed Livewire requests and web vitals marked on the timeline, a link to the replay in every log line. packstub/filament-session-replay adds the sessions to a Filament panel.

packstub/session-replay via Laravel News
cyberwizard-dev/
schedule-catchup
g4t.io
17

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Schedule Catchup replays missed Laravel scheduled tasks after downtime, with opt-in recovery, bounded retries, and access to the original scheduled date.

cyberwizard-dev/schedule-catchup via Laravel News