I'm trying to write an artisan command. I've got the basics working.
Now I'm trying to clean things up by moving some of the code to another file.
The trouble is, in that other file, commands like $this-line('hello')
don't work.
Is there an easy way to make that work?
(two files below, first file is the command and it works. note in the bottom of the 'working' file, we do $tmp = new viewclass
then $tmp->display()
The second file is where I want to put all the logic - how do I call inherited functions like $this->line, $this->info, $this->table, etc... from that second file?
CrudFromDb_view.php:
<?php
namespace path\laravel_crudfromdb\Commands;
use Illuminate\Console\Command;
use \path\laravel_crudfromdb\Classes\viewclass;
class CrudFromDb_Views extends Command
{
protected $signature = 'z:viewviews';
protected $description = 'Displays generated views on screen. Does not change or create any files';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->line(' THIS LINE WORKS');
$tmp = new viewclass;
$tmp->display(); // <- Fails, see 'viewclass.php' file below
}
}
viewclass.php:
<?php
namespace path\laravel_crudfromdb\Classes;
class viewclass extends Command
{
protected $env;
protected $dbhost;
protected $dbname;
protected $dbuser;
protected $dbpw;
protected $connection;
function __construct()
{
// parent::__construct();
}
function display()
{
//this fails!
//how can I call this 'line' function?
$this->line('This is a line');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire