#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 →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

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 →

Laravel Artisan Console: Common Commands

Artisan is Laravel's built-in command-line interface, and it's one of the framework's most time-saving tools. Instead of manually creating boilerplate files or running raw database commands, Artisan automates the repetitive parts of development.

What Is Artisan?

Every Laravel project ships with an artisan script in its root folder. Running it through PHP gives access to dozens of built-in commands, and custom commands can be added for project-specific tasks like data imports or scheduled maintenance.

Frequently Used Commands

CommandWhat It Does
php artisan serveStarts a local development server
php artisan make:modelGenerates a new Eloquent model class
php artisan make:controllerGenerates a new controller class
php artisan migrateRuns pending database migrations
php artisan route:listDisplays every registered route in the application
php artisan tinkerOpens an interactive shell for testing code directly

Why It Matters

Many Artisan commands, especially those touching the database, rely on settings defined in one central place — the .env file — which is exactly what we cover next.

Generators That Save the Most Time

The make: family accepts flags that create several related files in one go. Learning a few of them removes a lot of repetitive setup.

php artisan make:model Post -mcr      # model + migration + resource controller
php artisan make:model Order -a       # model with migration, factory, seeder, policy, controller and form requests
php artisan make:request StorePostRequest
php artisan make:middleware EnsureUserIsActive
php artisan list make                 # every generator available in your version

If you forget what a command accepts, php artisan help migrate prints its arguments and options. php artisan about shows the environment, cache status and drivers in use, which is handy when something behaves differently on two machines.

Database and Cache Commands

CommandUse it when
php artisan migrate:statusYou want to see which migrations have run
php artisan migrate:rollbackYou need to undo the last batch of migrations
php artisan migrate:fresh --seedYou want a clean local database with sample data
php artisan db:seedYou only want to run seeders
php artisan optimize:clearConfig, route or view caches seem stale
php artisan config:cacheYou are deploying and want faster config loading
php artisan down / upYou need maintenance mode during a deployment
php artisan queue:workYou need a worker to process queued jobs

Be careful: migrate:fresh drops every table before re-running migrations. It is perfect on a laptop and destructive on a live server. On production, prefer plain migrate with the --force flag, and take a database backup first.

Writing Your Own Command

Custom commands are ideal for jobs you run repeatedly, such as sending a report or cleaning old records. Generate the class first:

php artisan make:command PruneOldDrafts

Then fill in the signature and the handle() method in app/Console/Commands/PruneOldDrafts.php:

class PruneOldDrafts extends Command
{
    protected $signature = 'drafts:prune {--days=30 : Delete drafts older than this}';
    protected $description = 'Delete unpublished drafts older than the given number of days';

    public function handle(): int
    {
        $days = (int) $this->option('days');
        $count = Post::where('status', 'draft')
            ->where('updated_at', '<', now()->subDays($days))
            ->delete();

        $this->info("Deleted {$count} old drafts.");
        return self::SUCCESS;
    }
}

The signature does two jobs: it names the command and declares its inputs. Text in curly braces without dashes is a required argument, while --days=30 defines an option with a default value. The text after the colon becomes the help description shown by php artisan help drafts:prune.

Run it with php artisan drafts:prune --days=60. Recent Laravel versions discover commands in that folder automatically, and the same command can be added to the scheduler so it runs on its own.

Common Mistakes With Artisan

  • Running config:cache and then calling env() outside config files; cached config means those calls return null.
  • Forgetting to clear caches after changing routes or .env values on a server.
  • Running Artisan with a different PHP version than the web server uses.
  • Putting heavy logic inside the command instead of a service class that can also be tested and reused.

Practical habit: keep a short list of the commands your project uses for setup, testing and deployment in the README so every developer runs them the same way.

Ready to master Laravel Training Course?

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

Explore Course