Laravel and Lumen Auto Hard Deleter

Overview

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

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.

You might also like...
A collection of generators for Lumen and Laravel 5.

Lumen generators A collection of generators for Lumen and Laravel 5. Contents Why ? Installation Quick Usage Detailed Usage Model Generator Migration

CORS (Cross-Origin Resource Sharing) support for Laravel and Lumen

Description This package adds Cross-Origin Resource Sharing (CORS) support to your Laravel application. The package is based on Framework agnostic (PS

A Laravel and Lumen Badges Generator

Laravel and Lumen Badge Generator That package is a easy wrapper to Badges/Poser. #Installing composer require vluzrmos/laravel-badge-poser Laravel co

Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.
Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

Cascade delete and restore when using the Laravel or Lumen SoftDeletes feature.

Public API for the project coding.events. Made in PHP 8.0 with Lumen 8, PHP-FPM, NGINX and MySQL 8.
Public API for the project coding.events. Made in PHP 8.0 with Lumen 8, PHP-FPM, NGINX and MySQL 8.

coding.events API Uma API feita apenas para passar o tempo, montando uma API para o site coding.events. Sinta-se livre para usar esse código como es

 Provides a Eloquent query builder for Laravel or Lumen
Provides a Eloquent query builder for Laravel or Lumen

This package provides an advanced filter for Laravel or Lumen model based on incoming requets.

Laravel Lumen service provider for Understand.io

The service provider is deprecated - it does not support error grouping. Laravel Lumen service provider for Understand.io You may also be interested i

🔐 JSON Web Token Authentication for Laravel & Lumen
🔐 JSON Web Token Authentication for Laravel & Lumen

Documentation Documentation for 1.* here For version 0.5.* See the WIKI for documentation. Supported by Auth0 If you want to easily add secure authent

Simple Video is a automated H264 encryption system built on Lumen Laravel Framework

Simple Video is a automated H264 encryption system built on Lumen Laravel Framework

Comments
  • Scrutinizer Auto-Fixes

    Scrutinizer Auto-Fixes

    @SiavashBamshadnia requested this pull request.

    It consists of patches automatically generated for this project on Scrutinizer: https://scrutinizer-ci.com/g/SiavashBamshadnia/Laravel-Auto-Hard-Deleter/

    opened by scrutinizer-auto-fixer 0
Releases(1.3.0)
Owner
Siavash Bamshadnia
Web and Android developer
Siavash Bamshadnia
Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

VatCalculator Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a st

Dries Vints 1.1k Jan 7, 2023
Auto-generated Interface and Repository file via Repository pattern in Laravel

Auto-generated Repository Pattern in Laravel A repository is a separation between a domain and a persistent layer. The repository provides a collectio

Ngo Dinh Cuong 11 Aug 15, 2022
Use auto generated UUID slugs to identify and retrieve your Eloquent models.

Laravel Eloquent UUID slug Summary About Features Requirements Installation Examples Compatibility table Alternatives Tests About By default, when get

Khalyomede 25 Dec 14, 2022
Auto generate routes for Laravel Livewire components

livewire-auto-routes Auto generate routes for Laravel Livewire Components. Requirements Livewire 2 Laravel 8 php 8 Installation composer require tanth

Tina Hammar 19 May 11, 2022
Auto Generate laravel api Documentation

Laravel Dark Documentation Generator ?? You can create Documentation for your api easily by using this library Installation: Require this package with

HusseinAlaa 6 May 8, 2022
PHP Simple Response, XML, JSON,... auto response with accept in request's header

simple-response Simple package to handle response properly in your API. This package does not include any dependency. Install Via Composer $ composer

Phuong Danh 3 Dec 8, 2021
A system for auto-decorating models with presenters

Laravel Auto Presenter 7 This package automatically decorates objects bound to views during the view render process. Features Automatically decorate o

Laravel Auto Presenter 754 Dec 21, 2022
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Laravel Responder - a package for building API responses, integrating Fractal into Laravel and Lumen

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.

Alexander Tømmerås 776 Dec 25, 2022
📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.

Laravel Package Support for Lumen: Makes Lumen compatible with Laravel Packages. You can use any Laravel Packages in Lumen by installing Larasupport Package.

Irfaq Syed 127 Dec 17, 2022