1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 05:24: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();
}
}