Laravel soft delete children when parent soft deletes

Overview

Laravel Soft Deletes Parent

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


Automatically soft delete a model's children while maintaining their own soft deleted state when you restore the parent model. After installing the trait below, the Post model's parent_deleted_at will update whenever an Author model is deleted or restored. This allows you to maintain the original deleted_at for the Post model after Author is restored. The Post model will scope queries to exclude any where the parent is deleted.


Installation

You can install the package via composer:

composer require dillingham/soft-deletes-parent

Usage

Add the parent_deleted_at column to your table:

Schema::table('posts', function (Blueprint $table) {
    $table->softDeletesParent();
});

And add the trait and parent model to your child model:

<?php

namespace App\Models;

use Dillingham\SoftDeletesParent\SoftDeletesParent;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use SoftDeletesParent;
}
<?php

namespace App\Providers;

class AppServiceProvider
{
    public function register()
    {
        Post::softDeletesParent(Author::class);
    }
}

Scopes

With parent trashed:

Post::withParentTrashed()->get();

Only parent trashed:

Post::onlyParentTrashed()->get();

Testing

composer test

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.

You might also like...
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster.

Laravel Kickstart What is Laravel Kickstart? Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster. It com

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Laravel Sanctum support for Laravel Lighthouse
Laravel Sanctum support for Laravel Lighthouse

Lighthouse Sanctum Add Laravel Sanctum support to Lighthouse Requirements Installation Usage Login Logout Register Email Verification Forgot Password

Bring Laravel 8's cursor pagination to Laravel 6, 7

Laravel Cursor Paginate for laravel 6,7 Installation You can install the package via composer: composer require vanthao03596/laravel-cursor-paginate U

A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Comments
  • Will not install

    Will not install

    > composer require dillingham/soft-deletes-parent
    Info from https://repo.packagist.org: #StandWithUkraine
    Using version ^0.0.2 for dillingham/soft-deletes-parent
    ./composer.json has been updated
    Running composer update dillingham/soft-deletes-parent
    Loading composer repositories with package information
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Root composer.json requires dillingham/soft-deletes-parent ^0.0.2 -> satisfiable by dillingham/soft-deletes-parent[0.0.2].
        - dillingham/soft-deletes-parent 0.0.2 requires illuminate/contracts ^8.37 -> found illuminate/contracts[v8.37.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
    
    You can also try re-running composer require with an explicit version constraint, e.g. "composer require dillingham/soft-deletes-parent:*" to figure out if any version is installable, or "composer require dillingham/soft-deletes-parent:^2.1" if you know which you need.
    
    Installation failed, reverting ./composer.json and ./composer.lock to their original content.
    
    opened by Sophist-UK 0
Releases(0.0.2)
Owner
Brian Dillingham
Brian Dillingham
e-soft.uz source code

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Elbek Khamdullaev 4 Dec 6, 2022
An open source Laravel Soundboard with Admin Panel CRUD (Create Read Update Delete) built on Laravel, Bootstrap, and Vue.js

Laravel Soundboard An open source Laravel Soundboard with Admin Panel CRUD (Create Read Update Delete) built on Laravel 5.8, Bootstrap 4, Vue.js, Boot

Jeremy Kenedy 24 Oct 28, 2022
Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration.

Migrator Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration. Installation: To install Migrator you

Reza Amini 457 Jan 8, 2023
Perform Bulk/Batch Update/Insert/Delete with laravel.

Bulk Query Perform Bulk/Batch Update/Insert/Delete with laravel. Problem I tried to make bulk update with laravel but i found that Laravel doesn't sup

Mohamed Samir 9 Dec 14, 2021
A laravel package to handle cascade delete and restore on model relations.

Laravel Model Soft Cascade A laravel package to handle cascade delete and restore on model relations. This package not only handle the cascade delete

Touhidur Rahman 18 Apr 29, 2022
Cascade Delete & Restore when using Laravel SoftDeletes

Laravel/Lumen Soft Cascade Delete & Restore Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature. Why do I need it? To make

Asked.io 669 Nov 30, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022
Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

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

Asked.io 669 Nov 30, 2022
A laravel package for cascding SoftDeletes delete/restore actions

This is a Laravel 8 package for cascding SoftDeletes delete/restore actions. Laravel 7.0 is supported since v0.1.0 Laravel 8.0 is supported since v0.1

Razi Alsayyed 9 Mar 20, 2022
Locust are malware that can delete all folders, files, etc. on the system; I

Locust are malware that can delete all folders, files, etc. on the system; It was originally designed for web systems.

Md. Ridwanul Islam Muntakim 21 Dec 9, 2022