PHP code example of sbamtr / laravel-auto-hard-deleter

1. Go to this page and download the library: Download sbamtr/laravel-auto-hard-deleter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sbamtr / laravel-auto-hard-deleter example snippets


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Prunable;

class SampleModel extends Model
{
    use SoftDeletes, Prunable;

    /**
     * Define which records should be pruned.
     */
    public function prunable()
    {
        // Delete records soft deleted more than 30 days ago
        return static::where('deleted_at', '<=', now()->subDays(30));
    }
}

use Illuminate\Support\Facades\Schedule;

Schedule::command('model:prune')->daily();

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

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

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

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

const AUTO_HARD_DELETE_AFTER = '5 months';

class SampleModel extends Model
{
    use SoftDeletes;
    const AUTO_HARD_DELETE_ENABLED = true;
    const AUTO_HARD_DELETE_AFTER = '5 months';
}
bash
php artisan vendor:publish --provider="sbamtr\LaravelAutoHardDeleter\AutoHardDeleteServiceProvider" --tag=config
bash
php artisan hard-delete-expired