我创建了一个laravel命令,如下:
class CreateFirstUserCommand extends Command
{
protected $signature = 'firsttenant:create {name}';
protected $description = 'Creates first user in database with name';
public function handle()
{
$name = $this->argument('name');
$website = new Website();
app(WebsiteRepository::class)->create($website);
$hostname = new Hostname;
$hostname->fqdn = $name.'.site.me';
$hostname = app(HostnameRepository::class)->create($hostname);
app(HostnameRepository::class)->attach($hostname, $website);
$tenancy = app(Environment::class);
$tenancy->hostname($hostname);
// resolves $hostname as currently active hostname
$tenancy->hostname();
// switches the tenant and reconfigures the app
$tenancy->tenant($website);
// resolves $website
$tenancy->website();
// resolves $website
$tenancy->tenant();
$tenancy->identifyHostname();
sleep(10);
$role = Role::create(['name' => 'tenant']);
$permission = Permission::create(['name' => 'all']);
$user= new User();
$user->name = $name;
$user->email = 'admin@'.$name.'.site.me';
$user->password = Hash::make('12344321');
$user->assignRole('tenant');
$user->save();
}
}
我从控制台调用此命令的方式为:
php artisan firsttenant:创建Alpha
并按预期工作正常,但是当我从代码中调用时如下:
Artisan :: call('firsttenant:create',['name'=> $ name]);
它不执行任何操作。