Closed bolechen closed 5 years ago
$ laravel new model-cleanup && cd model-cleanup
$ composer require spatie/laravel-model-cleanup
$ composer require --dev nunomaduro/larastan
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Builder;
use Spatie\ModelCleanup\GetsCleanedUp;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Authenticatable implements GetsForcedCleanedUp
{
use Notifiable;
use SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public static function cleanUp(Builder $query) : Builder
{
// Delete all records older than a year
return $query->onlyTrashed()->where('deleted_at', '<', Carbon::now()->subDay());
}
}
$ php artisan code:analyse
Feel free to PR improvements.
the code is
ref link https://github.com/nunomaduro/larastan/issues/40