call(function () { $this->delete_expired_shared_links(); })->hourly(); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__ . '/Commands'); require base_path('routes/console.php'); } /** * Get and delete expired shared links */ protected function delete_expired_shared_links(): void { // Get all shares with expiration time $shares = Share::whereNotNull('expire_in')->get(); $shares->each(function ($share) { // Get dates $created_at = Carbon::parse($share->created_at); // If time was over, then delete share record if ($created_at->diffInHours(Carbon::now()) >= $share->expire_in) { $share->delete(); } }); } }