chore: code refactor via rector
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -26,15 +26,14 @@ class Log extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public static function deleteLogsFromDB()
|
||||
public static function deleteLogsFromDB(): string
|
||||
{
|
||||
$cutoff = Carbon::now('UTC')->subMonths(3)->toDateTimeString();
|
||||
$count = count(self::where('created_at', '<', $cutoff)
|
||||
->orderBy('created_at', 'desc')
|
||||
$cutoff = Date::now('UTC')->subMonths(3)->toDateTimeString();
|
||||
$count = count(self::query()->where('created_at', '<', $cutoff)->latest()
|
||||
->get());
|
||||
|
||||
if ($count > 0) {
|
||||
self::where('created_at', '<', $cutoff)->delete();
|
||||
self::query()->where('created_at', '<', $cutoff)->delete();
|
||||
|
||||
return "$count old log(s) deleted from the database.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user