PHP code example of codenco-dev / laravel-eloquent-pruning

1. Go to this page and download the library: Download codenco-dev/laravel-eloquent-pruning 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/ */

    

codenco-dev / laravel-eloquent-pruning example snippets


    'models' => [
        App\MyModel::class,
        App\MySecondModel::class,
    ],
bash
php artisan vendor:publish --provider="CodencoDev\LaravelEloquentPruning\LaravelEloquentPruningServiceProvider" --tag="config"
 php
    /**
     * Scope that allows filter records for pruning.
     */
    public function scopeCouldBePruned(Builder $query): Builder
    {
        return $query->where('status','done');
    }
 php
    /**
     * Define if the active record can be pruned, if the ProcessWithDeleteEvents is true.
     */
    public function canBePruned(): bool
    {
        //tests, extern call etc.
        return MyService::checkMyModelIsDeletable($this->id);
    }
 php
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('pruning:start')->hourly();
    }
 php
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('pruning:start --hours=48])->hourly();
    }
 php
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function(){
            (new MyModel)->prune();
        })->daily();
    }