1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 18:04:03 +00:00

add tenant:tinker command

This commit is contained in:
Samuel Štancl 2024-04-03 19:46:27 +02:00
parent 29d1469651
commit 6f4b9dadf1
4 changed files with 28 additions and 29 deletions

26
src/Commands/Tinker.php Normal file
View file

@ -0,0 +1,26 @@
<?php
namespace Stancl\Tenancy\Commands;
use Laravel\Tinker\Console\TinkerCommand as BaseTinker;
use Symfony\Component\Console\Input\InputArgument;
class Tinker extends BaseTinker
{
public $name = 'tenant:tinker';
protected function getArguments()
{
return array_merge([
['tenant', InputArgument::OPTIONAL, 'The tenant to run Tinker for. Pass the tenant key or leave null to default to the first tenant.'],
], parent::getArguments());
}
public function handle()
{
// ?: to support empty strings so that the original argument (`include`) can be reached even with a falsy tenant argument
tenancy()->initialize($this->argument('tenant') ?: tenancy()->model()::first());
parent::handle();
}
}

View file

@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Concerns;
use Symfony\Component\Console\Input\InputArgument;
trait HasATenantArgument
{
protected function getArguments()
{
return array_merge([
['tenant', InputArgument::REQUIRED, 'Tenant id', null],
], parent::getArguments());
}
protected function getTenants(): array
{
return [tenancy()->find($this->argument('tenant'))];
}
public function __construct()
{
parent::__construct();
$this->specifyParameters();
}
}

View file

@ -85,6 +85,7 @@ class TenancyServiceProvider extends ServiceProvider
Commands\Down::class,
Commands\Link::class,
Commands\Seed::class,
Commands\Tinker::class,
Commands\Install::class,
Commands\Migrate::class,
Commands\Rollback::class,