ajaycalicut17/laravel-trash
Composer 安装命令:
composer require ajaycalicut17/laravel-trash
包简介
Laravel package to manage soft delete.
README 文档
README
The Laravel "soft delete" functionality is effectively managed through the use of this package. It works like trash in your system.
Installation ⚙️
- You can install the package via composer:
composer require ajaycalicut17/laravel-trash
- Run migrations to create tables for this package:
php artisan migrate
- Check model is "soft delete" able, this package work by using laravel "soft delete" functionality:
<?php namespace App\Models; + use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { + use SoftDeletes; }
- To enable this package for a model, add the Ajaycalicut17\LaravelTrash\Traits\Trashable trait to the Eloquent model:
<?php namespace App\Models; + use Ajaycalicut17\LaravelTrash\Traits\Trashable; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { + use SoftDeletes, Trashable; }
- To start listening "trashed" model event, define a $dispatchesEvents property on your Eloquent model:
<?php namespace App\Models; + use Ajaycalicut17\LaravelTrash\Events\MoveToTrash; use Ajaycalicut17\LaravelTrash\Traits\Trashable; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use SoftDeletes, Trashable; + + /** + * The event map for the model. + * + * @var array + */ + protected $dispatchesEvents = [ + 'trashed' => MoveToTrash::class, + ]; }
- To override the trash name (Optional):
<?php namespace App\Models; use Ajaycalicut17\LaravelTrash\Events\MoveToTrash; use Ajaycalicut17\LaravelTrash\Traits\Trashable; + use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use SoftDeletes, Trashable; /** * The event map for the model. * * @var array */ protected $dispatchesEvents = [ 'trashed' => MoveToTrash::class, ]; + + public static function trashName(Model $model): string + { + return static::class.' '.$model->id; + } }
- Publishing the config file (Optional):
php artisan vendor:publish --provider="Ajaycalicut17\LaravelTrash\LaravelTrashServiceProvider" --tag="config"
- To periodically delete the model from the trash, add model:prune Artisan command in your application's App\Console\Kernel class and change the config\trash.php pruning status to "true", you can also enter your pruning period here. (Optional):
+ use Ajaycalicut17\LaravelTrash\Models\Trash; /** * Define the application's command schedule. */ protected function schedule(Schedule $schedule): void { + $schedule->command('model:prune', [ + '--model' => Trash::class, + ])->daily(); }
Usage 🔨
- To get all trash model data:
Trash::all();
- To get all trash model and associated model data:
Trash::with('trashable')->get();
- To restore associated model form trash:
Trash::first()->restoreFromTrash();
- To delete trashed model and associated model:
Trash::first()->deleteFromTrash();
- To delete all trashed model and associated model:
Trash::emptyTrash();
Testing 🧪
composer test
Changelog 🚀
Please see CHANGELOG for more information what has changed recently.
Contributing 🤝
Please see CONTRIBUTING for details.
Credits 🔥
License 📃
The MIT License (MIT). Please see License File for more information.
ajaycalicut17/laravel-trash 适用场景与选型建议
ajaycalicut17/laravel-trash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「model」 「laravel」 「delete」 「eloquent」 「restore」 「trash」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ajaycalicut17/laravel-trash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ajaycalicut17/laravel-trash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ajaycalicut17/laravel-trash 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
SoftDelete plugin for CakePHP
Laravel console command for deleting temp files and associated model instances.
Interfaces for web resource models and services to retrieve and create them
Laravel 5 - Repositories to the database layer
This package provides an Address Model, Migration and Factory. It also provides the traits HasBillingAddres and HasPublicAddress
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-15