Skip to content

Commit

Permalink
Fix calc of files size
Browse files Browse the repository at this point in the history
  • Loading branch information
henryavila committed Sep 1, 2023
1 parent 06e4a60 commit 84426e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ Integrate the multitenancy single database in Laravel Nova.
This package is based on https://spatie.be/docs/laravel-multitenancy. So logic and config of spatie/laravel-multitenancy
still aplies

## v2.0.0
Another option to don't define the tenant to an route is set the following `default` data to route declaration
```php
Route::get('/', [Controller::class, 'index'])
->defaults(\HenryAvila\LaravelNovaMultitenancy\LaravelNovaMultitenancy::SKIP_ROUTE, true);
```

If the `Tenant` has `domains` relationship, allow to define the current tenant based on current domain.
The `domains` relation model, must contain an `fqdn` attribute with the fqdn domain


Allow to run a invokable class when tenant is selected (See config file)

## Installation

Expand Down Expand Up @@ -118,7 +106,7 @@ Route::middleware('tenant')->group(function() {
```


If you receite an error: `Route [login] not defined.`.
If you receive an error: `Route [login] not defined.`.
Remember to change the route from `login` to `nova.login` in your `App\Http\Middleware\Authenticate` file
```php
protected function redirectTo($request)
Expand All @@ -127,6 +115,16 @@ protected function redirectTo($request)
}
```


Another option to don't define the tenant to an route is set the following `default` data to route declaration
```php
Route::get('/', [Controller::class, 'index'])
->defaults(\HenryAvila\LaravelNovaMultitenancy\LaravelNovaMultitenancy::SKIP_ROUTE, true);
```

If the `Tenant` has `domains` relationship, allow to define the current tenant based on current domain.
The `domains` relation model, must contain an `fqdn` attribute with the fqdn domain

## Testing

```bash
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "henryavila/laravel-nova-multitenancy",
"version": "3.0.3",
"version": "3.0.4",
"description": "Integrate the multi tenancy single database in Laravel Nova.",
"keywords": [
"henryavila",
Expand Down
12 changes: 7 additions & 5 deletions src/Traits/ModelWithTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ trait ModelWithTenant
/**
* Name of all columns from this model that has the size of the file
*/
protected static array $fileSizeColumns = [];
protected static function getFileSizeColumns(): array {
return [];
}

public function __construct(array $attributes = [])
{
Expand All @@ -40,13 +42,13 @@ protected static function booted(): void

static::created(function (Model $file) {
$file->load('tenant');
foreach (static::$fileSizeColumns as $column) {
foreach (static::getFileSizeColumns() as $column) {
$file->tenant->updateDiskUsage($file->$column);
}
});

static::updating(function (Model $file) {
foreach (static::$fileSizeColumns as $column) {
foreach (static::getFileSizeColumns() as $column) {
if ($file->isDirty($column)) {

$file->load('tenant');
Expand All @@ -58,7 +60,7 @@ protected static function booted(): void

if (in_array(SoftDeletes::class, class_uses(static::class))) {
static::forceDeleted(function (Model $file) {
foreach (static::$fileSizeColumns as $column) {
foreach (static::getFileSizeColumns() as $column) {
$originalSize = $file->getOriginal($column);
if ($originalSize) {
$file->load('tenant');
Expand All @@ -68,7 +70,7 @@ protected static function booted(): void
});
} else {
static::deleted(function (Model $file) {
foreach (static::$fileSizeColumns as $column) {
foreach (static::getFileSizeColumns() as $column) {
$originalSize = $file->getOriginal($column);
if ($originalSize) {
$file->load('tenant');
Expand Down

0 comments on commit 84426e8

Please sign in to comment.