PHPackages                             kobalazs/laravel-restrict-soft-deletes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kobalazs/laravel-restrict-soft-deletes

ActiveUtility[Utility &amp; Helpers](/categories/utility)

kobalazs/laravel-restrict-soft-deletes
======================================

Restrict deletes for Eloquent models that implement soft deletes.

33.1kPHP

Since Nov 13Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kobalazs/laravel-restrict-soft-deletes)[ Packagist](https://packagist.org/packages/kobalazs/laravel-restrict-soft-deletes)[ RSS](/packages/kobalazs-laravel-restrict-soft-deletes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-restrict-soft-deletes
=============================

[](#laravel-restrict-soft-deletes)

Restrict deletes for Eloquent models that implement soft deletes. Based on the idea of Michael Dyrynda at

Installation
============

[](#installation)

Run `composer require kobalazs/laravel-restrict-soft-deletes`

Usage
=====

[](#usage)

1. Use RestrictSoftDeletes in your Model you want to have restricted
2. Add a protected attibute to your Model class listing the Eloquent relationships to be watched
3. In case of an attempted deletion on a restricted model the trait will throw a `Netpok\Database\Support\DeleteRestrictionException` (HTTP 403)

Example
=======

[](#example)

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Netpok\Database\Support\RestrictSoftDeletes;

class User extends Model
{
    use SoftDeletes;
    use RestrictSoftDeletes;

    /**
     * The relations restricting model deletion
     */
    protected $restrictDeletes = ['posts'];

    /**
     * Eloquent relationship (has to be defined for RestrictSoftDeletes to work!)
     */
    public function posts()
    {
        return $this->hasMany('App\Post');
    }

    ...
}

```

In this example a User can not be deleted while they have any Post that is not soft-deleted.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 92.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cac5be22dd474af5d832a7edd0719d4e0d3988b9e8e73dc11e78ece8273c793e?d=identicon)[kobalazs](/maintainers/kobalazs)

---

Top Contributors

[![balazs-kovacs](https://avatars.githubusercontent.com/u/33684471?v=4)](https://github.com/balazs-kovacs "balazs-kovacs (13 commits)")[![kobalazs](https://avatars.githubusercontent.com/u/3484057?v=4)](https://github.com/kobalazs "kobalazs (1 commits)")

### Embed Badge

![Health badge](/badges/kobalazs-laravel-restrict-soft-deletes/health.svg)

```
[![Health](https://phpackages.com/badges/kobalazs-laravel-restrict-soft-deletes/health.svg)](https://phpackages.com/packages/kobalazs-laravel-restrict-soft-deletes)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
