New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

ddzobov/laravel-pivot-softdeletes

Make your Eloquent models pivots be able to soft deleted in Laravel/Lumen
714,374 69
Install
composer require ddzobov/laravel-pivot-softdeletes
Latest Version:2.4.0
Laravel:5 – 13
License:MIT
Last Updated:Aug 19, 2026
Links: GitHub  ·  Packagist
Maintainer: zobov

Laravel pivot SoftDeletes for Laravel 5.8 to 12.x

Installation

Require this package with composer:

composer require ddzobov/laravel-pivot-softdeletes

Basic usage

use DDZobov\PivotSoftDeletes\Model;

class Post extends Model
{
    public function tags()
    {
        return $this->belongsToMany(Tag::class)->withSoftDeletes();
    }
}

class Tag extends Model
{
    public function posts()
    {
        return $this->belongsToMany(Post::class)->withSoftDeletes();
    }
}

Custom pivot model:

use DDZobov\PivotSoftDeletes\Model;
use DDZobov\PivotSoftDeletes\Relations\Pivot;

class Post extends Model
{
    public function tagsWithCustomPivot()
    {
        return $this->belongsToMany(Tag::class)->using(PostTag::class)->withSoftDeletes();
    }
}

class Tag extends Model
{
    public function postsWithCustomPivot()
    {
        return $this->belongsToMany(Post::class)->using(PostTag::class)->withSoftDeletes();
    }
}

class PostTag extends Pivot
{
    
}

Custom deleted_at field:

$this->belongsToMany(Post::class)->withSoftDeletes('custom_deleted_at');

Show without trashed (default behavior):

// withoutTrashed() already called inside withSoftDeletes()
$this->belongsToMany(Post::class)->withSoftDeletes();

// same behavior
$this->belongsToMany(Post::class)->withSoftDeletes()->withoutTrashedPivots();

Show exists & trashed:

$this->belongsToMany(Post::class)->withSoftDeletes()->withTrashedPivots();

Show only trashed:

$this->belongsToMany(Post::class)->withSoftDeletes()->onlyTrashedPivots();

Restore pivot recods:

$post->tags()->restore([$tag->id]);

Restore pivot recods (with custom pivot):

$post->tagsWithCustomPivot()->restore([$tag->id]);

Force detach pivot records:

$post->tags()->forceDetach([$tag->id]);

Sync with force detaching pivot records:

$post->tags()->syncWithForceDetaching([$tag->id]);

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

Related Packages

kiendaotac/lumen-installer

Lumen application installer.

12 0
appzcoder/lumen-routes-list

Display the route list of Lumen

747,431 117
codeception/module-lumen

Codeception module for Lumen framework

167,947 0
mlntn/lumen-artisan-serve

artisan serve for Lumen projects

100,473 49
cosmicvelocity/lumen-helpers

Improves interoperability between Lumen and Laravel.

65,662 6

Version History

Version Released Laravel License
2.4.0 >=5.8 <11.0|^11.0|^12.0|^13.0 MIT
2.3.1 >=5.8 <11.0|^11.0|^12.0 MIT
2.3.0 >=5.8 <11.0|^11.0 ^12.0 MIT
2.2.0 >=5.8 <11.0|^11.0 MIT
2.1.4 >=5.8 <11.0 MIT