Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit a52e0a5

Browse files
author
Artem Brezhnev
authored
Merge pull request #49 from dmyers/patch-2
[2.1] Added support for customizing tenant model
2 parents 266c4eb + 0cdb0d0 commit a52e0a5

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

config/saml2.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
return [
44

5+
/*
6+
|--------------------------------------------------------------------------
7+
| Tenant Model
8+
|--------------------------------------------------------------------------
9+
|
10+
| This will allow you to override the tenant model with your own.
11+
|
12+
*/
13+
14+
'tenantModel' => \Slides\Saml2\Models\Tenant::class,
15+
516
/*
617
|--------------------------------------------------------------------------
718
| Use built-in routes

src/Commands/CreateTenant.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Slides\Saml2\Commands;
44

55
use Slides\Saml2\Helpers\ConsoleHelper;
6+
use Slides\Saml2\Models\Tenant;
67
use Slides\Saml2\Repositories\TenantRepository;
78

89
/**
@@ -93,7 +94,8 @@ public function handle()
9394
return;
9495
}
9596

96-
$tenant = new \Slides\Saml2\Models\Tenant([
97+
$class = config('saml2.tenantModel', Tenant::class);
98+
$tenant = new $class([
9799
'key' => $key,
98100
'uuid' => \Ramsey\Uuid\Uuid::uuid4(),
99101
'idp_entity_id' => $entityId,

src/Commands/RendersTenants.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Slides\Saml2\Commands;
44

5+
use Slides\Saml2\Models\Tenant;
56
use Illuminate\Support\Str;
67

78
/**
@@ -22,7 +23,7 @@ trait RendersTenants
2223
protected function renderTenants($tenants, string $title = null)
2324
{
2425
/** @var \Slides\Saml2\Models\Tenant[]|\Illuminate\Database\Eloquent\Collection $tenants */
25-
$tenants = $tenants instanceof \Slides\Saml2\Models\Tenant
26+
$tenants = $tenants instanceof Tenant
2627
? collect([$tenants])
2728
: $tenants;
2829

@@ -53,7 +54,7 @@ protected function renderTenants($tenants, string $title = null)
5354
*
5455
* @return array
5556
*/
56-
protected function getTenantColumns(\Slides\Saml2\Models\Tenant $tenant)
57+
protected function getTenantColumns(Tenant $tenant)
5758
{
5859
return [
5960
'ID' => $tenant->id,
@@ -79,7 +80,7 @@ protected function getTenantColumns(\Slides\Saml2\Models\Tenant $tenant)
7980
*
8081
* @return void
8182
*/
82-
protected function renderTenantCredentials(\Slides\Saml2\Models\Tenant $tenant)
83+
protected function renderTenantCredentials(Tenant $tenant)
8384
{
8485
$this->output->section('Credentials for the tenant');
8586

src/Repositories/TenantRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class TenantRepository
2020
*/
2121
public function query(bool $withTrashed = false)
2222
{
23-
$query = Tenant::query();
23+
$class = config('saml2.tenantModel', Tenant::class);
24+
$query = $class::query();
2425

2526
if($withTrashed) {
2627
$query->withTrashed();

src/ServiceProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ protected function bootRoutes()
4949
*/
5050
protected function bootPublishes()
5151
{
52-
$this->publishes([
53-
__DIR__ . '/../config/saml2.php' => config_path('saml2.php'),
54-
]);
52+
$source = __DIR__ . '/../config/saml2.php';
53+
54+
$this->publishes([$source => config_path('saml2.php')]);
55+
$this->mergeConfigFrom($source, 'saml2');
5556
}
5657

5758
/**

0 commit comments

Comments
 (0)