PHPackages                             robotsinside/laravel-deletable - 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. robotsinside/laravel-deletable

ActiveLibrary

robotsinside/laravel-deletable
==============================

Gracefully handle deletion of Eloquent models with related entities.

1.5.0(3y ago)11.2k1MITPHPPHP &gt;=7.2.5|^8.0

Since Sep 19Pushed 3y agoCompare

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

READMEChangelog (10)Dependencies (7)Versions (12)Used By (0)

Laravel Deletable
=================

[](#laravel-deletable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/86df0de8920ced016b6fb3f76d4f6bf1479f671d1f2360bebfcaca90c4b0bef7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f626f7473696e736964652f6c61726176656c2d64656c657461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robotsinside/laravel-deletable)[![Total Downloads](https://camo.githubusercontent.com/c3ef11e99154332c5317eee5591346a16254c07d4dfbb6f61a914eeea19f525f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f626f7473696e736964652f6c61726176656c2d64656c657461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robotsinside/laravel-deletable)[![CI](https://github.com/robotsinside/laravel-deletable/actions/workflows/laravel.yml/badge.svg)](https://github.com/robotsinside/laravel-deletable/actions/workflows/laravel.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/458425f8985b0b0c8a736cffe75e05a098e3d77906acddbcad2bfc54492a4e02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

This package can be used to gracefully handle the deletion of Eloquent models which are related to other models through `HasOne`, `HasMany`, `BelongsTo`, `BelongsToMany` or `Morph*` relationships.

It provides a number of helpful additions:

1. Validate delete requests with the provided `DeletableRequest` class
2. Check for the existence of related models before soft deleting a model instance
3. Emulate the cascade behaviour provided at the DB layer

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Use cases](#use-cases)
    - [1. Avoid SQLSTATE\[23000\]: Integrity constraint violation](#1-avoid-sqlstate-23000---integrity-constraint-violation)
    - [2. Check if a model is deletable](#2-check-if-a-model-is-deletable)
    - [3. Validate deletes](#3-validate-deletes)
    - [4. Customising the validation message](#4-customising-the-validation-messages)
- [Supported safeDelete modes (use when soft deleting)](#supported-safedelete-modes-use-when-soft-deleting)
    - [Exception mode (default)](#exception-mode-default)
    - [Cascade mode](#cascade-mode)
    - [Custom mode](#custom-mode)
- [Testing](#testing)
- [Security](#security)
- [Coffee Time](#coffee-time)
- [License](#license)

Installation
------------

[](#installation)

1. Run `composer require robotsinside/laravel-deletable`.
2. Optionally register the service provider in `config/app.php`

```
/*
* Package Service Providers...
*/
\RobotsInside\DeletableServiceProvider::class,
```

Auto-discovery is enabled, so this step can be skipped.

Usage
-----

[](#usage)

Use the `RobotsInside\Deletable\Deletable` trait in your models. You must also define a protected `deletableConfig()` method which returns the configuration array.

```
