Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mlezcano1985/laravel-pivot-soft-deletes
(DEPRECATED) Soft delete Eloquent pivot models using Laravel SoftDeletes trait
https://github.com/mlezcano1985/laravel-pivot-soft-deletes
deprecated deprecated-repo laravel laravel-softdeletes-trait pivot-soft-deletes soft-deletes softdeletes trait
Last synced: about 2 months ago
JSON representation
(DEPRECATED) Soft delete Eloquent pivot models using Laravel SoftDeletes trait
- Host: GitHub
- URL: https://github.com/mlezcano1985/laravel-pivot-soft-deletes
- Owner: mlezcano1985
- License: mit
- Created: 2017-12-08T21:18:46.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-30T23:31:41.000Z (almost 5 years ago)
- Last Synced: 2024-10-07T04:23:33.379Z (3 months ago)
- Topics: deprecated, deprecated-repo, laravel, laravel-softdeletes-trait, pivot-soft-deletes, soft-deletes, softdeletes, trait
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 18
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DEPRECATED
This is no longer supported, please consider using another package instead.# Pivot soft deletes for the Laravel PHP Framework
Easy and fast way to soft deletes Eloquent pivot models using Laravel [SoftDeletes](https://laravel.com/docs/eloquent#soft-deleting) trait.# Installation
This trait is installed via [Composer](http://getcomposer.org/). To install, simply add to your `composer.json` file:
```
$ composer require mlezcano1985/laravel-pivot-soft-deletes
```
# Example
Include SoftDeletes and PivotSoftDeletes in Many to Many models.
```php
belongsToMany(Role::class);
}/**
* Automatically creates hash for the user password.
*
* @param string $value
* @return void
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = Hash::make($value);
}
}
```
and
```php
belongsToMany(Account::class);
}
}
```
Now we can use `detach()` method on Account model to softdelete the pivot table
```php
$account = App\Role::find($role_id)->accounts()->findOrFail($account_id)
$account->detach(); // Soft delete the Intermediate Table
```
## Defining Custom Intermediate Table Model
If 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:
```php
/**
* @return BelongsToMany
*/
public function roles()
{
return $this->belongsToMany(Role::class)->using(AccountRole::class);
}
```
but is hight reccommended to include **SoftDeletes** trait on custom pivot model
```php
accounts()->findOrFail($account_id)
$account->detach(); // Soft delete the Intermediate Table
```# Support
If you are having general issues with this package, feel free to contact me on [Twitter](https://twitter.com/mlezcano1985).If 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.
If you're using this package, I'd love to hear your thoughts. Thanks!