Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real Time Facades: Deleting framework directories for tenants solution #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions source/docs/v3/realtime-facades.blade.md
Original file line number Diff line number Diff line change
@@ -63,3 +63,40 @@ class CreateFrameworkDirectoriesForTenant
}
}
```

## Deleting framework directories for tenants {#deleting-framework-directories-for-tenants}

If you used the previous solution and created the framework directories for a tenant, then you may be interested in
deleting the framework directories once the tenant has been destroyed. Similarly, you will have to create a new `Job` that
will remove any framework files created previously.

Similarly, create a new `Job` like the one below, and add the `Job` to the `TenantDeleted` job pipeline

```php
<?php

namespace App\Jobs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\File;
use Stancl\Tenancy\Contracts\Tenant;

class DeleteFrameworkDirectoriesForTenant implements ShouldQueue
{
protected Tenant $tenant;

public function __construct(Tenant $tenant)
{
$this->tenant = $tenant;
}

public function handle(): void
{
$this->tenant->run(function ($tenant) {
$storage_path = storage_path();

File::deleteDirectory($storage_path);
});
}
}
```