All Projects → SiavashBamshadnia → Laravel-Auto-Hard-Deleter

SiavashBamshadnia / Laravel-Auto-Hard-Deleter

Licence: MIT license
Laravel and Lumen Auto Hard Deleter

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Laravel-Auto-Hard-Deleter

response
Response HTTP package for Simfony, Laravel, Lumen and PHP 7 with standard REST API
Stars: ✭ 14 (-58.82%)
Mutual labels:  lumen, laravel-package, lumen-package
laravel-snowflake
This Laravel package to generate 64 bit identifier like the snowflake within Twitter.
Stars: ✭ 94 (+176.47%)
Mutual labels:  lumen, laravel-package, lumen-package
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (+1002.94%)
Mutual labels:  eloquent, lumen
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: ✭ 19 (-44.12%)
Mutual labels:  eloquent, laravel-package
baserepo
Base repository
Stars: ✭ 71 (+108.82%)
Mutual labels:  lumen, lumen-package
eloquent-repository
Repository pattern for Eloquent ORM with focus in cache.
Stars: ✭ 30 (-11.76%)
Mutual labels:  eloquent, laravel-package
query-filter
Define filters for your Eloquent models based on your request
Stars: ✭ 20 (-41.18%)
Mutual labels:  eloquent, laravel-package
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (+129.41%)
Mutual labels:  eloquent, laravel-package
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+838.24%)
Mutual labels:  lumen, laravel-package
Laravel Deletable
👾 Gracefully restrict deletion of Laravel Eloquent models
Stars: ✭ 137 (+302.94%)
Mutual labels:  eloquent, laravel-package
Eloquent Relativity
Allows you to decouple your eloquent models from one another.
Stars: ✭ 112 (+229.41%)
Mutual labels:  eloquent, laravel-package
Laravel Auditing
Record the change log from models in Laravel
Stars: ✭ 2,210 (+6400%)
Mutual labels:  eloquent, lumen
Laravel Source Encrypter
Laravel and Lumen Source Code Encrypter
Stars: ✭ 175 (+414.71%)
Mutual labels:  lumen, laravel-package
Laravel Url Shortener
Powerful URL shortening tools in Laravel
Stars: ✭ 80 (+135.29%)
Mutual labels:  lumen, laravel-package
LaraPersonate
Login as a different user quickly
Stars: ✭ 121 (+255.88%)
Mutual labels:  eloquent, laravel-package
Laravel Sensitive
过滤敏感词汇的laravel包,使用DFA算法
Stars: ✭ 63 (+85.29%)
Mutual labels:  lumen, laravel-package
Eloquent Ldap
A Laravel 5.1 package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.
Stars: ✭ 19 (-44.12%)
Mutual labels:  eloquent, laravel-package
video-downloader
Video Downloader for Facebook.
Stars: ✭ 63 (+85.29%)
Mutual labels:  lumen, laravel-package
Laravel Postal Code Validation
Worldwide postal code validation for Laravel and Lumen
Stars: ✭ 278 (+717.65%)
Mutual labels:  lumen, laravel-package
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (+132.35%)
Mutual labels:  eloquent, laravel-package

Laravel Auto Hard Deleter

PHP Composer Build Status StyleCI Latest Stable Version License PHP from Travis config CodeFactor

This package deletes soft deleted rows automatically after a time interval that you define.

For Laravel and Lumen 6, 7, 8, 9

Installation

Step 1

Require the package with composer using the following command:

composer require sbamtr/laravel-auto-hard-deleter

Step 2

For Laravel

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    \sbamtr\LaravelAutoHardDeleter\AutoHardDeleteServiceProvider::class,
];

For Lumen

Add this line of code under the Register Service Providers section of your bootstrap/app.php:

$app->register(\sbamtr\LaravelAutoHardDeleter\AutoHardDeleteServiceProvider::class);

Step 3

Now its the time for scheduling the command. in you app/Console/Kernel.php file, paste this code in schedule() function:

protected function schedule(Schedule $schedule)
{
    // ...
    $schedule->command(\sbamtr\LaravelAutoHardDeleter\HardDeleteExpiredCommand::class)->hourly();
    // ...
}

In the code above, the command scheduled to run hourly. you can change it. For more information, please read this page.

Step 4 (Optional)

You can publish the config file with this following command:

php artisan vendor:publish --provider="sbamtr\LaravelAutoHardDeleter\AutoHardDeleteServiceProvider" --tag=config

Note: If you are using Lumen, you have to use this package.

Also you can set the AUTO_HARD_DELETE_AFTER value in .env file. like the following code:

...
AUTO_HARD_DELETE_AFTER='1 day'
...

Usage

in your models that used SoftDeletes trait, you can enable Auto Hard Delete with this code:

class SampleModel extends Model
{
    use SoftDeletes;
    const AUTO_HARD_DELETE_ENABLED = true;
}

Just write const AUTO_HARD_DELETE_ENABLED = true in your models! Also you can set expiration time for your deleted entities using the following line:

const AUTO_HARD_DELETE_AFTER = '5 months';

In the code above, expiration time for your soft deleted entity model is 5 months. The final code is:

class SampleModel extends Model
{
    use SoftDeletes;
    const AUTO_HARD_DELETE_ENABLED = true;
    const AUTO_HARD_DELETE_AFTER = '5 months';
}

You can set any other values for AUTO_HARD_DELETE_AFTER like 5(means 5 days), 2 hours, 45 days, 2.5 months, 1 year, etc.

Note: If you don't set any value for AUTO_HARD_DELETE_AFTER in your model, the soft deleted models with AUTO_HARD_DELETE_ENABLED = true will be hard deleted after the time defined in config file named auto-hard-deleter.php.

Auto Hard Delete Command

Also you can hard delete expired rows manually using this artisan command:

php artisan hard-delete-expired

Written with by Siavash Bamshadnia

Please support me by staring this repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].