How to echo to console in Laravel and Artisan?

0 votes

I'm using Laravel and Artisan for my migrations. Is there a method to output information to the console? I can't seem to find any information on this. For example:

<?php

class Generate_Sample_Users{

    public function up(){

        //Echo to console here
        echo "Creating sample users...";

        $generator = new Sample_Data();
        $user_count = 30;
        $users = array();


        for($i=0; $i < $user_count; $i++){
            array_push($users, $generator->generate_user($i));
        }

        DB::table('users')->insert($users);
    }

    public function down(){
        DB::table('users')->delete();
    }

}

Apr 3 in Laravel by kartik
• 11,290 points
34 views

1 answer to this question.

0 votes

Hello @kartik,

You can try this as this works for me

use Symfony\Component\Console\Output\ConsoleOutput;

class MigrateData {

    public function up()
    {
        $output = new ConsoleOutput();

        for($i=0; $i<50000; $i++)
        {
             $output->writeln('Converting '.$i.' of 50000');
        }
     }
}

I have a migration which is converting a large table into a more efficient format and use this to get some progress while it works.

Hope this works fine!!
Thank You!!

answered Apr 3 by Niroj
• 22,790 points

Related Questions In Laravel

0 votes
1 answer

What is database migration and How to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,790 points
55 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24 in Laravel by Niroj
• 22,790 points
34 views
0 votes
1 answer

How to set port for php artisan.php serve in Laravel?

Hii @kartik, When we use the php artisan serve ...READ MORE

answered Mar 30 in Laravel by Niroj
• 22,790 points
154 views
0 votes
1 answer

How to get data from Laravel backend and display in Vue/Nuxt frontend

Hello, You have to use the package dotenv. Then ...READ MORE

answered Apr 8 in Laravel by Niroj
• 22,790 points
75 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,790 points
434 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,790 points
62 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,790 points
64 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,790 points
151 views
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,790 points
224 views
0 votes
1 answer

Explain validations in laravel and How to validate my application incoming data?

Hey @kartik, In Programming validations are a handy ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,790 points
58 views