diff --git a/app/Console/Commands/CheckForExpiredOneTimePasswords.php b/app/Console/Commands/CheckForExpiredOneTimePasswords.php new file mode 100644 index 0000000..0532547 --- /dev/null +++ b/app/Console/Commands/CheckForExpiredOneTimePasswords.php @@ -0,0 +1,39 @@ +info('Checking for expired one-time passwords...'); + $expiredOneTimePasswords = OneTimePassword::where('expires_at', '<', now()) + ->where('status', 'pending') + ->get(); + $expiredOneTimePasswords->each(function ($otp) { + $otp->update(['status' => 'expired']); + }); + $this->info('Expired one-time passwords checked and updated.'); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a644ba9..880376b 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -4,6 +4,7 @@ use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use Illuminate\Support\Facades\Log; class Kernel extends ConsoleKernel { @@ -12,9 +13,14 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule): void { - // $schedule->command('inspire')->hourly(); $schedule->command('sanctum:prune-expired --hours=24')->daily(); - //delete expired otps + $schedule->command('app:check-for-expired-one-time-passwords')->everyMinute() + ->onSuccess(function () { + Log::info('Expired one-time passwords checked and updated.'); + }) + ->onFailure(function () { + Log::error('Expired one-time passwords check failed.'); + }); } /** diff --git a/app/Http/Controllers/BillboardController.php b/app/Http/Controllers/BillboardController.php index 0b0b190..c03d72d 100644 --- a/app/Http/Controllers/BillboardController.php +++ b/app/Http/Controllers/BillboardController.php @@ -32,6 +32,7 @@ public function agentBillboards(Request $request) return response()->json([ 'billboards' => $agent->billboards() ->active() + ->orderBy('updated_at', 'desc') ->with('district:id,name') ->get() diff --git a/app/Models/Billboard.php b/app/Models/Billboard.php index 90c8e49..304a5b1 100644 --- a/app/Models/Billboard.php +++ b/app/Models/Billboard.php @@ -38,14 +38,24 @@ public static function boot() protected $hidden = [ 'created_at', 'deleted_at', + 'created_by', + 'updated_at', + 'district_id', ]; protected $casts = [ 'is_active' => 'boolean', ]; + protected $appends = [ + 'updated_at_human', + ]; + + public function getUpdatedAtHumanAttribute() + { + return $this->updated_at->diffForHumans(); + } - //Scope Active public function scopeActive($query) { return $query->where('is_active', true);