diego-betalabs / laravel5-soft-cascade by diego-betalabs
forked from Askedio/laravel-soft-cascade

Soft Delete & Restore Cascader
12,728
0
2
Package Data
Maintainer Username: diego-betalabs
Package Create Date: 2017-04-20
Package Last Update: 2017-04-25
Home Page: https://asked.io/cascading-softdeletes-with-laravel-5
Language: PHP
License: Unknown
Last Refreshed: 2024-05-08 03:10:11
Package Statistics
Total Downloads: 12,728
Monthly Downloads: 285
Daily Downloads: 14
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Header

Build Status Codacy Badge StyleCI Badge

Laravel/Lumen 5 Soft Cascade Delete & Restore

Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

Why do I need it?

To make soft deleting and restoring relations easy.

If you enjoy features like MySQL cascade deleting but want to use Laravels SoftDeletes feature you'll need to do some extra steps to ensure your relations are properly deleted or restored.

This package is intended to replace those steps with a simple array that defines the relations you want to cascade.

Installation

Install with composer

composer require askedio/laravel5-soft-cascade

Register the service provider in your config/app.php

Laravel:

Askedio\SoftCascade\Providers\GenericServiceProvider::class,

Lumen:

Askedio\SoftCascade\Providers\LumenServiceProvider::class,

Usage

In your Model enable the trait and define $softCascade. Example.

use \Askedio\SoftCascade\Traits\SoftCascadeTrait;

protected $softCascade = ['profiles'];

$softCascade is an array of your relation names, in the example you'll see we've defined function profiles() for the relation.

Nested relations work by defining $softCascade in the related Model as you can see here.

After you've defined your relations you can simply trigger delete() or restore() on your Model and your relations will have the same task performed.

User::first()->delete();
User::withTrashed()->first()->restore();

Supported Databases

  • MySQL
  • SQLite

Testing

I have written some very basic tests, certainly more needs to be done here. If you find this useful please help by testing other databases or writing better unit tests because I must move on.

Issues & Contributing

I will be using this with MySQL in a new API so any issues I find related to my use will be resolved. If you find an issue with MySQL please report it and I will fix it.

If you are using another database and have issues please contribute by submitting a pull request. I do not have time to test this with other database but assume all would work.