ddzobov/laravel-pivot-softdeletes
最新稳定版本:2.3.1
Composer 安装命令:
composer require ddzobov/laravel-pivot-softdeletes
包简介
Make your Eloquent models pivots be able to soft deleted in Laravel/Lumen
README 文档
README
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.
统计信息
- 总下载量: 437.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 67
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-17