ajaycalicut17/laravel-trash is a Laravel package for laravel package to manage soft delete..
It currently has 5 GitHub stars and 25 downloads on Packagist (latest version v1.0.3).
Install it with composer require ajaycalicut17/laravel-trash.
Discover more Laravel packages by ajaycalicut17
or browse all Laravel packages to compare alternatives.
Last updated
The Laravel "soft delete" functionality is effectively managed through the use of this package. It works like trash in your system.
composer require ajaycalicut17/laravel-trash
php artisan migrate
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use SoftDeletes;
}
<?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;
}
<?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,
];
}
<?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;
}
}
php artisan vendor:publish --provider="Ajaycalicut17\LaravelTrash\LaravelTrashServiceProvider" --tag="config"
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();
}
Trash::all();
Trash::with('trashable')->get();
Trash::first()->restoreFromTrash();
Trash::first()->deleteFromTrash();
Trash::emptyTrash();
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.