{"id":19368831,"url":"https://github.com/mlezcano1985/laravel-pivot-soft-deletes","last_synced_at":"2025-04-23T15:30:59.412Z","repository":{"id":57018197,"uuid":"113618263","full_name":"mlezcano1985/laravel-pivot-soft-deletes","owner":"mlezcano1985","description":"(DEPRECATED) Soft delete Eloquent pivot models  using Laravel SoftDeletes trait","archived":false,"fork":false,"pushed_at":"2020-01-30T23:31:41.000Z","size":14,"stargazers_count":18,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-07T04:23:33.379Z","etag":null,"topics":["deprecated","deprecated-repo","laravel","laravel-softdeletes-trait","pivot-soft-deletes","soft-deletes","softdeletes","trait"],"latest_commit_sha":null,"homepage":"","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/mlezcano1985.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":"2017-12-08T21:18:46.000Z","updated_at":"2021-10-11T17:10:16.000Z","dependencies_parsed_at":"2022-08-22T11:31:43.178Z","dependency_job_id":null,"html_url":"https://github.com/mlezcano1985/laravel-pivot-soft-deletes","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Flaravel-pivot-soft-deletes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Flaravel-pivot-soft-deletes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Flaravel-pivot-soft-deletes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Flaravel-pivot-soft-deletes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlezcano1985","download_url":"https://codeload.github.com/mlezcano1985/laravel-pivot-soft-deletes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223926907,"owners_count":17226454,"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":["deprecated","deprecated-repo","laravel","laravel-softdeletes-trait","pivot-soft-deletes","soft-deletes","softdeletes","trait"],"created_at":"2024-11-10T08:08:56.739Z","updated_at":"2024-11-10T08:08:57.256Z","avatar_url":"https://github.com/mlezcano1985.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DEPRECATED\nThis is no longer supported, please consider using another package instead.\n\n# Pivot soft deletes for the Laravel PHP Framework\nEasy and fast way to soft deletes Eloquent pivot models using Laravel [SoftDeletes](https://laravel.com/docs/eloquent#soft-deleting) trait.\n\n# Installation\nThis trait is installed via [Composer](http://getcomposer.org/). To install, simply add to your `composer.json` file:\n```\n$ composer require mlezcano1985/laravel-pivot-soft-deletes\n```\n# Example\nInclude SoftDeletes and PivotSoftDeletes in Many to Many models.\n```php\n\u003c?php\nnamespace App;\n\nuse Mlezcano1985\\Database\\Support\\PivotSoftDeletes;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany;\nuse Illuminate\\Database\\Eloquent\\SoftDeletes;\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Illuminate\\Support\\Facades\\Hash;\n\nclass Account extends Authenticatable\n{\n    use Notifiable, SoftDeletes, PivotSoftDeletes;\n\n    /**\n     * The attributes that should be mutated to dates.\n     *\n     * @var array\n     */\n    protected $dates = ['deleted_at'];\n    }\n\n    /**\n     * @return BelongsToMany\n     */\n    public function roles()\n    {\n        return $this-\u003ebelongsToMany(Role::class);\n    }\n\n    /**\n     * Automatically creates hash for the user password.\n     *\n     * @param  string $value\n     * @return void\n     */\n    public function setPasswordAttribute($value)\n    {\n        $this-\u003eattributes['password'] = Hash::make($value);\n    }\n}\n```\nand\n```php\n\u003c?php\nnamespace App;\n\nuse Mlezcano1985\\Database\\Support\\PivotSoftDeletes;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany;\nuse Illuminate\\Database\\Eloquent\\SoftDeletes;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Role extends Model\n{\n    use SoftDeletes, PivotSoftDeletes;\n\n    /**\n     * The attributes that should be mutated to dates.\n     *\n     * @var array\n     */\n    protected $dates = ['deleted_at'];\n    }\n\n    /**\n     * @return BelongsToMany\n     */\n    public function accounts()\n    {\n        return $this-\u003ebelongsToMany(Account::class);\n    }\n}\n```\nNow we can use `detach()` method on Account model to softdelete the pivot table\n```php\n$account = App\\Role::find($role_id)-\u003eaccounts()-\u003efindOrFail($account_id)\n$account-\u003edetach(); // Soft delete the Intermediate Table\n```\n## Defining Custom Intermediate Table Model\nIf we want to define a [Custom Intermediate Table Model](https://laravel.com/docs/eloquent-relationships#many-to-many), the process works in the same way. For example:\n```php\n/**\n * @return BelongsToMany\n */\npublic function roles()\n{\n    return $this-\u003ebelongsToMany(Role::class)-\u003eusing(AccountRole::class);\n}\n```\nbut is hight reccommended to include **SoftDeletes** trait on custom pivot model\n```php\n\u003c?php\nnamespace App;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\Pivot;\nuse Illuminate\\Database\\Eloquent\\SoftDeletes;\n\nclass AccountRole extends Pivot\n{\n    use SoftDeletes;\n\n    /**\n     * The attributes that should be mutated to dates.\n     *\n     * @var array\n     */\n    protected $dates = ['deleted_at'];\n    }\n}\n```\nand now\n```php\n$account = App\\Role::find($role_id)-\u003eaccounts()-\u003efindOrFail($account_id)\n$account-\u003edetach(); // Soft delete the Intermediate Table\n```\n\n# Support\nIf you are having general issues with this package, feel free to contact me on [Twitter](https://twitter.com/mlezcano1985).\n\nIf you believe you have found an issue, please report it using the [GitHub issue tracker](https://github.com/mlezcano1985/laravel-pivot-soft-deletes/issues), or better yet, fork the repository and submit a pull request.\n\nIf you're using this package, I'd love to hear your thoughts. Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlezcano1985%2Flaravel-pivot-soft-deletes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlezcano1985%2Flaravel-pivot-soft-deletes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlezcano1985%2Flaravel-pivot-soft-deletes/lists"}