#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Using Closures and Artisan Commands for Scheduled Tasks

Scheduled tasks in Laravel aren't limited to full Artisan commands. Simple, one-off logic can be scheduled directly as a closure, without creating a dedicated command class at all.

Scheduling a Closure

$schedule->call(function () {
    DB::table('recent_visits')->delete();
})->daily();

This is convenient for small maintenance tasks that don't warrant their own command file.

Scheduling an Artisan Command

$schedule->command('reports:generate --detailed')->dailyAt('01:00');

Artisan commands are the better choice when the task is reusable, needs to be run manually as well, or requires its own arguments and options.

Combining Constraints

$schedule->command('emails:send')
    ->daily()
    ->weekdays()
    ->withoutOverlapping();

withoutOverlapping() is particularly useful for long-running tasks, preventing a new run from starting if the previous one hasn't finished yet.

Choosing Between the Two

That wraps up task scheduling and, with it, the full arc of this course — from routing and Blade through Eloquent, authentication, file handling, APIs, events, queues, and now scheduled automation.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course