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

2.4.1 #24

Merged
merged 28 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
275cfca
Merge pull request #3 from BinarCode/master
arthurkirkosa Jan 3, 2021
18cad27
Allow Laravel 9
arthurkirkosa Feb 8, 2022
ed5275e
Merge pull request #4 from BinarCode/master
arthurkirkosa Feb 8, 2022
f18d36e
Merge pull request #19 from arthurkirkosa/l9
binaryk Feb 8, 2022
b1d8cf2
Laravel 10 Support
arthurkirkosa Feb 14, 2023
dae1ef5
Merge pull request #5 from BinarCode/master
arthurkirkosa Feb 14, 2023
7929213
Fix merge conflicts
arthurkirkosa Feb 14, 2023
4525bd7
Correct package version
arthurkirkosa Feb 14, 2023
900c928
Merge pull request #20 from arthurkirkosa/l10
binaryk Feb 15, 2023
1c27a4f
Fix Psalm
arthurkirkosa Feb 15, 2023
f619940
fix: adding helpers
binaryk Jul 10, 2023
cba2f7e
Fix styling
binaryk Jul 10, 2023
a027818
fix: wip
binaryk Jul 10, 2023
aef3104
fix: wip
binaryk Jul 10, 2023
852e393
Fix styling
binaryk Jul 10, 2023
3253891
fix: wip
binaryk Jul 10, 2023
118b88f
Merge branch '2.2.1' of github.com:BinarCode/laravel-tenantable into …
binaryk Jul 10, 2023
7589c86
fix: wip
binaryk Jul 10, 2023
6f6a627
fix: wip
binaryk Jul 10, 2023
759bc00
fix: wip
binaryk Jul 10, 2023
37c97dc
Merge pull request #21 from arthurkirkosa/l10
binaryk Jul 10, 2023
a1efa7c
fix: wip
binaryk Jul 10, 2023
438036d
Merge branch 'master' of github.com:BinarCode/laravel-tenantable into…
binaryk Jul 10, 2023
ca963e3
fix: wip
binaryk Jul 10, 2023
5a7819a
fix: reverting illuminate
binaryk Jul 11, 2023
7a7a06e
Merge branch 'main' into 2.4.1
binaryk Jul 11, 2023
474f526
fix: wip
binaryk Jul 11, 2023
05c4b03
Merge branch '2.4.1' of github.com:BinarCode/laravel-tenantable into …
binaryk Jul 11, 2023
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
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0]
laravel: [8.*]
php: [8.1]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: ^6.6
- laravel: 10.*
testbench: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpunit.cache
build
composer.lock
vendor
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
}
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.37"
"php": "^8.1",
"illuminate/contracts": "^10.0"
},
"require-dev": {
"brianium/paratest": "^6.2",
"nunomaduro/collision": "^5.3",
"orchestra/testbench": "^6.15",
"phpunit/phpunit": "^9.3",
"brianium/paratest": "^6.3",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.3.3",
"spatie/laravel-ray": "^1.9",
"vimeo/psalm": "^4.4"
},
Expand Down
13 changes: 10 additions & 3 deletions config/tenantable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use BinarCode\Tenantable\Models\Tenant;

return [
/**
* The name of the table in the database.
Expand All @@ -13,15 +15,15 @@
*
* If the entry does have null tenant_id, it will be considered as a global entry.
*/
'allow_nullable_tenant' => env('ALLOW_NULLABLE_TENANT', true),
'allow_nullable_tenant' => env('ALLOW_NULLABLE_TENANT', false),

/**
* The base model for tenant.
*/
'model' => BinarCode\Tenantable\Models\TenantContract::class,
'model' => Tenant::class,

/*
* Domain for the maine application
* Domain for the main application
*/
'master_domain' => env('MASTER_DOMAIN', 'sample.test'),

Expand All @@ -30,6 +32,11 @@
*/
'master_fqdn' => env('MASTER_FQDN', 'admin.sample.test'),

/**
* The HTTP protocol.
*/
'protocol' => env('PROTOCOL', 'https'),

/*
* The connection name to reach the a tenant database.
*
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
findUnusedCode="false"
findUnusedBaselineEntry="true"
findUnusedVariablesAndParams="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
32 changes: 31 additions & 1 deletion src/Models/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use BinarCode\Tenantable\Models\Concerns\UsesMasterConnection;
use BinarCode\Tenantable\Tenant\Contracts\DatabaseConfig;
use BinarCode\Tenantable\Tenant\Contracts\Tenantable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function makeCurrentMaster()

public function isActive(): bool
{
return boolval($this->active);
return (bool) $this->active;
}

public function forget(): Tenantable
Expand All @@ -95,4 +96,33 @@ public function databaseConfig(): DatabaseConfig
{
return \BinarCode\Tenantable\Tenant\DatabaseConfig::make($this);
}

public function frontend(): Attribute
{
/**
* @psalm-suppress UndefinedFunction
*/
return new Attribute(
get: fn (
) => config('tenantable.protocol')."://{$this->subdomain}.".withoutProtocol(config('tenantable.master_domain')),
);
}

public function api(): Attribute
{
/**
* @psalm-suppress UndefinedFunction
*/
return new Attribute(
get: fn (
) => config('tenantable.protocol')."://{$this->subdomain}.".withoutProtocol(config('tenantable.master_domain')).'/api',
);
}

public function frontendRoute(string $route, array $query = []): string
{
$route = str($route)->whenStartsWith('/', fn ($str) => $str->replaceFirst('/', ''))->toString();

return "{$this->frontend}/{$route}".(count($query) ? '?'.http_build_query($query) : '');
}
}
1 change: 1 addition & 0 deletions src/Tenant/PendingNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use BinarCode\Tenantable\Models\Tenant;
use Illuminate\Contracts\Support\Arrayable;

/** @psalm-suppress MissingTemplateParam */
class PendingNew implements Arrayable
{
use Make;
Expand Down
7 changes: 7 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ function fromTenant($property = null)
{
return data_get(app(Tenantable::class), $property);
}

if (! function_exists('withoutProtocol')) {
function withoutProtocol(string $fqdn = ''): string
{
return str_replace(['https://', 'http://', 'www.'], ['https://' => '', 'http://' => '', 'www.' => ''], $fqdn);
}
}