1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 23:44:03 +00:00
tenancy/src/Database/Concerns/TenantRun.php
2025-01-05 15:50:30 +01:00

29 lines
615 B
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Closure;
use Illuminate\Foundation\Bus\PendingDispatch;
use Stancl\Tenancy\Contracts\Tenant;
/**
* @phpstan-require-implements Tenant
*/
trait TenantRun
{
/**
* Run a callback in this tenant's context.
*
* This method is atomic and safely reverts to the previous context.
*
* @template T
* @param Closure(Tenant): T $callback
* @return (T is PendingDispatch ? null : T)
*/
public function run(Closure $callback): mixed
{
return tenancy()->run($this, $callback);
}
}