简体   繁体   中英

Writing Artisan Command - Display Data from Database

I want to write a Artisan command for my Laravel Web App.

The command should display the records from a specific table of a database.

I already created a new command called Loginstats.php in the Commands folder , but I'm struggling with the logic....

I think it's could be work with something in that way:

public function handle() {
        DB::table('logincount')->orderBy ( 'customer_id' )->chunk ( 100, function ($users) {
            foreach ($users as $user) {
                //
            }
        } );
    }

What do I need to do, to get the data from the database?

Is it also possible with the common artisan commands from the Command.php ?

Thank you!

Since DB is a facade, you should use full namespace:

\DB::table...

Or add use DB to the top of the class after namespace clause:

use DB;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM