mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 02:54:05 +00:00
[2.2.0] Timestamps (#213)
* Timestamps * Apply fixes from StyleCI * Add void typehint * wip * Fix tests * Apply fixes from StyleCI
This commit is contained in:
parent
b0c8e92bb4
commit
31c9930c93
6 changed files with 124 additions and 4 deletions
46
src/Features/Timestamps.php
Normal file
46
src/Features/Timestamps.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
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', $this->now());
|
||||
$tenant->with('updated_at', $this->now());
|
||||
});
|
||||
|
||||
$tenantManager->hook('tenant.updating', function ($tm, Tenant $tenant) {
|
||||
$tenant->with('updated_at', $this->now());
|
||||
});
|
||||
|
||||
$tenantManager->hook('tenant.softDeleting', function ($tm, Tenant $tenant) {
|
||||
$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