mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 04:34:03 +00:00
Timestamps
This commit is contained in:
parent
b0c8e92bb4
commit
d3f9b58f8d
3 changed files with 37 additions and 2 deletions
|
|
@ -82,6 +82,7 @@ return [
|
||||||
// not needed for tenancy to be bootstrapped. They are run
|
// not needed for tenancy to be bootstrapped. They are run
|
||||||
// regardless of whether tenancy has been initialized.
|
// regardless of whether tenancy has been initialized.
|
||||||
|
|
||||||
|
// Stancl\Tenancy\Features\Timestamps::class,
|
||||||
// Stancl\Tenancy\Features\TenantConfig::class,
|
// Stancl\Tenancy\Features\TenantConfig::class,
|
||||||
// Stancl\Tenancy\Features\TelescopeTags::class,
|
// Stancl\Tenancy\Features\TelescopeTags::class,
|
||||||
// Stancl\Tenancy\Features\TenantRedirect::class,
|
// Stancl\Tenancy\Features\TenantRedirect::class,
|
||||||
|
|
|
||||||
27
src/Features/Timestamps.php
Normal file
27
src/Features/Timestamps.php
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Features;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Date;
|
||||||
|
use Stancl\Tenancy\Contracts\Feature;
|
||||||
|
use Stancl\Tenancy\Tenant;
|
||||||
|
use Stancl\Tenancy\TenantManager;
|
||||||
|
|
||||||
|
class Timestamps implements Feature
|
||||||
|
{
|
||||||
|
public function bootstrap(TenantManager $tenantManager)
|
||||||
|
{
|
||||||
|
$tenantManager->hook('tenant.creating', function ($tm, Tenant $tenant) {
|
||||||
|
$tenant->with('created_at', Date::now());
|
||||||
|
$tenant->with('updated_at', Date::now());
|
||||||
|
});
|
||||||
|
|
||||||
|
$tenantManager->hook('tenant.updating', function ($tm, Tenant $tenant) {
|
||||||
|
$tenant->with('updated_at', Date::now());
|
||||||
|
});
|
||||||
|
|
||||||
|
$tenantManager->hook('tenant.softDeleting', function ($tm, Tenant $tenant) {
|
||||||
|
$tenant->with('deleted_at', Date::now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ use ArrayAccess;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Config\Repository;
|
use Illuminate\Config\Repository;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Traits\ForwardsCalls;
|
use Illuminate\Support\Traits\ForwardsCalls;
|
||||||
use Stancl\Tenancy\Contracts\Future\CanDeleteKeys;
|
use Stancl\Tenancy\Contracts\Future\CanDeleteKeys;
|
||||||
|
|
@ -260,10 +261,16 @@ class Tenant implements ArrayAccess
|
||||||
*/
|
*/
|
||||||
public function softDelete(): self
|
public function softDelete(): self
|
||||||
{
|
{
|
||||||
$this->put('_tenancy_original_domains', $this->domains);
|
$this->manager->event('tenant.softDeleting', $this);
|
||||||
|
|
||||||
|
$this->put([
|
||||||
|
'_tenancy_original_domains' => $this->domains,
|
||||||
|
]);
|
||||||
$this->clearDomains();
|
$this->clearDomains();
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
|
$this->manager->event('tenant.softDeleted', $this);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -391,7 +398,7 @@ class Tenant implements ArrayAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a value.
|
* Set a value in the data array without saving into storage.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue