mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:14:04 +00:00
add tenant:tinker command
This commit is contained in:
parent
29d1469651
commit
6f4b9dadf1
4 changed files with 28 additions and 29 deletions
|
|
@ -18,6 +18,7 @@
|
|||
"php": "^8.2",
|
||||
"ext-json": "*",
|
||||
"illuminate/support": "^10.1|^11.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
"facade/ignition-contracts": "^1.0.2",
|
||||
"spatie/ignition": "^1.4",
|
||||
"ramsey/uuid": "^4.7.3",
|
||||
|
|
|
|||
26
src/Commands/Tinker.php
Normal file
26
src/Commands/Tinker.php
Normal 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue