我正在尝试使用https://laravel.com/docs/5.4/artisan
中的Laravel progress bar
但是我收到以下错误
(1/1) ErrorException
Undefined property: App\Http\Controllers\ImportDeviceController::$output
以下是我的代码:
$users = \App\Users::all();
$bar = $this->output->createProgressBar(count($users));
foreach ($users as $user) {
$this->performTask($user);
$bar->advance();
}
$bar->finish();
更新
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Http\Helpers\GlobalHelper;
use Illuminate\Support\Collection;
use App\Http\Helpers\ImportDeviceHelper;
use Illuminate\Support\Facades\Redirect;
use App\Http\Controllers\ImportController;
use Excel;
use XmlParser;
use Storage;
use Symfony\Component\Console\Helper\ProgressBar;
class ImportDeviceController extends Controller
{
public function __construct(Request $request)
{
$this->objGlobalHelper = new GlobalHelper;
$this->objImportDeviceHelper = new ImportDeviceHelper($request);
$this->objImportController = new ImportController($request);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function device()
{
$users = \App\Users::all();
$bar = $this->output->createProgressBar(count($users));
foreach ($users as $user) {
$this->performTask($user);
$bar->advance();
}
$bar->finish();
exit;
}