PHP code example of motomedialab / compliance

1. Go to this page and download the library: Download motomedialab/compliance 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/ */

    

motomedialab / compliance example snippets


namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Motomedialab\Compliance\Traits\ComplianceRules;
use Motomedialab\Compliance\Contracts\HasComplianceRules;

class User implements HasComplianceRules
{
    use ComplianceRules;    
}

return [
    'models' => [
        App\Models\User::class => [
            // the default date column to check on
            'column' => 'last_login_at',
            // the number of days (relative to `column`) before a record will looked at for deletion
            'delete_after_days' => 365 * 3,
            // the number of days between the record being marked for deletion and actually being deleted
            'deletion_grace_period' => 15,
        ],
    ],
];

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Motomedialab\Compliance\Traits\ComplianceRules;
use Motomedialab\Compliance\Contracts\HasComplianceRules;

class User implements HasComplianceRules
{
    use ComplianceRules;
    
    // override to only delete users that have never logged in
    public function complianceQueryBuilder() : Builder
    {
        // make sure you eager load any relationships that you need!
        return $this->newQuery()
            ->with('subscriptions')
            ->whereNull('last_login_at');    
    }
    
    // the default column to check against
    // (irrelevant if you are already overriding complianceQueryBuilder)
    public function complianceCheckColumn() : string
    {
        return 'last_login_at';
    }
    
    // manipulate the number of days before a record is marked for deletion
    // (irrelevant if you are already overriding complianceQueryBuilder)
    public function complianceDeleteAfterDays() : int
    {
       return 365;
    }
    
    // manipulate the number of days between marking for deletion
    // and actually deleting the model
    public function complianceGracePeriod() : int
    {
        return 50;
    }
    
    // here you can set a boolean flag to assert
    // whether it should be possible to delete the record.
    // this will be checked both initially and right before the record
    // is deleted.
    public function complianceMeetsDeletionCriteria(): bool
    {
        // example: only delete if a user has no subscriptions.
        return $this->subscriptions->count() === 0;
    }
}
bash
php artisan vendor:publish compliance
php artisan migrate