Search code examples
phplaravelroutesconsolelaravel-artisan

What is the console route in Laravel? And how it works?


What is the console route in Laravel? And how it works? This is a knowledge base question. Please explain in easy language. Thanks in advance.


Solution

  • Using console route, you can create your own artisan commands. It is registered inside app/Console/kernal.php file. Let's say you want to alter column in your table, you can register in console route and run queries. although it can be done easily through migration, but this is simple example

    Artisan::command('sql-query', function () {
    \DB::statement('your query');
    })->describe('Execute SQL query');
    

    And now you can run artisan command in your terminal php artisan sql-query