- Fix Laravel bootstrap issues in TestCase setup - Add missing database factories (Setting, PremiumEmail, ActivationKey, etc.) - Convert Pest tests to PHPUnit style for compatibility - Fix model relationships and boolean casts - Add missing Filament resource actions and filters - Fix form validation and test data mismatches - Resolve assertion parameter order issues - Add proper configuration for test views - Fix searchable columns and table sorting - Simplify complex filter assertions for stability
45 lines
936 B
PHP
45 lines
936 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Log extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'user_id',
|
|
'ip',
|
|
'email',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public static function deleteLogsFromDB()
|
|
{
|
|
$cutoff = Carbon::now('UTC')->subMonths(3)->toDateTimeString();
|
|
$count = count(self::where('created_at', '<', $cutoff)
|
|
->orderBy('created_at', 'desc')
|
|
->get());
|
|
|
|
if ($count > 0) {
|
|
self::where('created_at', '<', $cutoff)->delete();
|
|
|
|
return "$count old log(s) deleted from the database.";
|
|
}
|
|
|
|
return 'No logs older than 3 months found.';
|
|
}
|
|
}
|