{"id":21598114,"url":"https://github.com/matfish2/eloquent-cascade","last_synced_at":"2025-10-12T12:32:53.534Z","repository":{"id":62505087,"uuid":"50378398","full_name":"matfish2/eloquent-cascade","owner":"matfish2","description":"Cascading delete trait for Laravel's Eloquent","archived":false,"fork":false,"pushed_at":"2016-08-11T15:20:38.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-12T18:55:56.089Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/fish/eloquent-cascade","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matfish2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-25T20:22:17.000Z","updated_at":"2016-07-12T07:34:28.000Z","dependencies_parsed_at":"2022-11-02T12:30:40.680Z","dependency_job_id":null,"html_url":"https://github.com/matfish2/eloquent-cascade","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/matfish2/eloquent-cascade","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Feloquent-cascade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Feloquent-cascade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Feloquent-cascade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Feloquent-cascade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matfish2","download_url":"https://codeload.github.com/matfish2/eloquent-cascade/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Feloquent-cascade/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261782676,"owners_count":23208907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T18:11:19.977Z","updated_at":"2025-10-12T12:32:48.458Z","avatar_url":"https://github.com/matfish2.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Eloquent Cascading Delete\n\n[![Latest Stable Version](https://poser.pugx.org/fish/eloquent-cascade/v/stable)](https://packagist.org/packages/fish/eloquent-cascade) [![Total Downloads](https://poser.pugx.org/fish/eloquent-cascade/downloads)](https://packagist.org/packages/fish/eloquent-cascade) [![Latest Unstable Version](https://poser.pugx.org/fish/eloquent-cascade/v/unstable)](https://packagist.org/packages/fish/eloquent-cascade) [![License](https://poser.pugx.org/fish/eloquent-cascade/license)](https://packagist.org/packages/fish/eloquent-cascade) [![Build Status](https://travis-ci.org/matfish2/eloquent-cascade.svg?branch=master)](https://travis-ci.org/matfish2/eloquent-cascade)\n\nThis package offers a simple trait that leverages the Eloquent delete event to recursively delete all specified relations for a given model.\n\n## Installation\n\nBegin by installing this package through Composer. Edit your project's `composer.json` file to require `fish/eloquent-cascade`.\n\n    \"require\": {\n      \"fish/eloquent-cascade\": \"^1.0\"\n    }\n\n  Next, update Composer from the Terminal:\n\n    composer update\n\n## Usage\n\n1. Include the trait in a parent model and make the other models extend it:\n\n        namespace App;\n\n        use Illuminate\\Database\\Eloquent\\Model;\n        use Fish\\Cascade\\Cascade;\n\n        class BaseModel extends Model\n        {\n            use Cascade;\n        }\n\n1. Add the relations you wish to delete to a protected `$cascade` array on the model. e.g:\n\n        class User extends BaseModel\n        {\n\n            protected $cascade = ['author'];\n\n            public function author() {\n\n              return $this-\u003ehasOne(Author::class);\n\n            }\n        }\n\n        class Author extends BaseModel\n        {\n\n            protected $cascade = ['posts'];\n\n            public function user() {\n\n              return $this-\u003ebelongsTo(User::class);\n\n            }\n\n            public function posts() {\n\n              return $this-\u003ehasMany(Post::class);\n\n            }\n\n        }\n\n        class Post extends BaseModel\n        {\n\n          protected $cascade = ['comments'];\n\n          public function comments() {\n\n            return $this-\u003ehasMany(Comment::class);\n\n          }\n\n        }\n\n\nIf you are using a trait for polymorphic relations and want to add this relation to the `$cascade` array, override the protected `getCascade` method.\nSuppose you have a `Locale` trait:\n\n       trait Locale {\n\n        public function locale() {\n            return $this-\u003emorphMany(Locale::class, 'translatable');\n        }\n\n        protected function getCascade() {\n          return array_merge($this-\u003ecascade, ['locale']);\n        }\n\n       }\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatfish2%2Feloquent-cascade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatfish2%2Feloquent-cascade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatfish2%2Feloquent-cascade/lists"}