我想知道是否可以扩展或替换该php artisan tinker
命令,因此它首先要求进行身份验证,以此作为看门人可以使用它的一种方式。
我尝试了以下方法:
<?php
namespace App\Console\Commands;
use Laravel\Tinker\Console\TinkerCommand;
use Illuminate\Support\Facades\Auth;
class Tinker extends TinkerCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tinker';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$email = $this->ask('Login (email)');
$password = $this->secret('Password for '.$email);
if (!Auth::attempt(compact('email', 'password'))) {
$this->error('Invalid Credentials.');
return;
}
if (Auth::user()->cannot('use-tinker')) {
$this->error('Unauthorized.');
return;
}
parent::handle();
}
}
但我收到一个错误,因为我没有包含使用的 'include' 参数TinkerCommand@handle
public function handle()
{
$this->getApplication()->setCatchExceptions(false);
$config = new Configuration([
'updateCheck' => 'never',
]);
$config->getPresenter()->addCasters(
$this->getCasters()
);
$shell = new Shell($config);
$shell->addCommands($this->getCommands());
$shell->setIncludes($this->argument('include')); # <-------- include argument
if (isset($_ENV['COMPOSER_VENDOR_DIR'])) {
$path = $_ENV['COMPOSER_VENDOR_DIR'];
} else {
$path = $this->getLaravel()->basePath().DIRECTORY_SEPARATOR.'vendor';
}
$path .= '/composer/autoload_classmap.php';
$loader = ClassAliasAutoloader::register($shell, $path);
try {
$shell->run();
} finally {
$loader->unregister();
}
}
我不确定 include 参数是关于什么的。我尝试转储它,它是一个空数组。在这一点上,我想知道是否有更好的方法。