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, 2020 in Laravel by kartik
• 37,520 points
5,632 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, 2020 by Niroj
• 82,840 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, 2020 in Laravel by Niroj
• 82,840 points
2,360 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, 2020 in Laravel by Niroj
• 82,840 points
4,098 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, 2020 in Laravel by Niroj
• 82,840 points
17,725 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, 2020 in Laravel by Niroj
• 82,840 points
3,277 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,088 views
0 votes
1 answer

What is redirection in Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,017 views
0 votes
1 answer

How to install Laravel via composer?

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

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,951 views
+1 vote
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, 2020 in Laravel by Niroj
• 82,840 points
44,894 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, 2020 in Laravel by Niroj
• 82,840 points
11,929 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, 2020 in Laravel by Niroj
• 82,840 points
1,467 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP