mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:54:03 +00:00
wip
This commit is contained in:
parent
3174256bd2
commit
6ed68dfd7f
4 changed files with 69 additions and 6 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Features;
|
||||
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Stancl\Tenancy\Contracts\Feature;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
|
@ -11,19 +12,35 @@ use Stancl\Tenancy\TenantManager;
|
|||
|
||||
class Timestamps implements Feature
|
||||
{
|
||||
/** @var Repository */
|
||||
protected $config;
|
||||
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function bootstrap(TenantManager $tenantManager): void
|
||||
{
|
||||
$tenantManager->hook('tenant.creating', function ($tm, Tenant $tenant) {
|
||||
$tenant->with('created_at', Date::now());
|
||||
$tenant->with('updated_at', Date::now());
|
||||
$tenant->with('created_at', $this->now());
|
||||
$tenant->with('updated_at', $this->now());
|
||||
});
|
||||
|
||||
$tenantManager->hook('tenant.updating', function ($tm, Tenant $tenant) {
|
||||
$tenant->with('updated_at', Date::now());
|
||||
$tenant->with('updated_at', $this->now());
|
||||
});
|
||||
|
||||
$tenantManager->hook('tenant.softDeleting', function ($tm, Tenant $tenant) {
|
||||
$tenant->with('deleted_at', Date::now());
|
||||
$tenant->with('deleted_at', $this->now());
|
||||
});
|
||||
}
|
||||
|
||||
public function now(): string
|
||||
{
|
||||
// Add this key to your tenancy.php config if you need to change the format.
|
||||
return Date::now()->format(
|
||||
$this->config->get('tenancy.features.timestamps.format') ?? 'c' // ISO 8601
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue