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.1] Added support for customizing tenant model #49

Merged
merged 4 commits into from
Feb 11, 2023

Conversation

dmyers
Copy link
Contributor

@dmyers dmyers commented Nov 18, 2022

The benefit of this is that it allows applications to customize a bit of the model say to add more attributes to fillable or add relationships to other models which is what I'm looking to do since I have added a foreign key to another table in my database. It also resolves #27.

For example all I would have to do with these changes is update the config/saml2.php file with this:

return [
    'tenantModel' => \App\Models\Saml2Tenant::class,
];

And then I can subclass this package's model in my application and I'm able to start using the new one right away to customize for my use cases.

src/Commands/CreateTenant.php Outdated Show resolved Hide resolved
@@ -20,7 +20,8 @@ class TenantRepository
*/
public function query(bool $withTrashed = false)
{
$query = Tenant::query();
$class = config('saml2.tenantModel');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here.

Btw, we could also have something like Saml2::newModelIntance() to have one resolver function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that return the Model::newModelInstance() or Model::query() that it currently uses? Not sure which is preferred in that case.

Like I have this change stashed if you like it:

<?php

namespace Slides\Saml2;

use Slides\Saml2\Models\Tenant;

class Saml2
{
    public static function tenantModel()
    {
        $class = config('saml2.tenantModel', Tenant::class);
        return $class::query();
    }
}

@breart breart changed the base branch from master to 2.1-dev November 20, 2022 12:18
@breart breart changed the title Added support for customizing tenant model [2.1] Added support for customizing tenant model Nov 20, 2022
@dmyers dmyers requested a review from breart November 21, 2022 18:15
@dmyers
Copy link
Contributor Author

dmyers commented Dec 8, 2022

@brezzhnev Do you think this looks good or have any thoughts on changing it more?

@dmyers
Copy link
Contributor Author

dmyers commented Jan 18, 2023

@brezzhnev Any thoughts here? I'd really like to be able to use this and customize the model without forking or anything if you have time to review.

@breart breart merged commit a52e0a5 into 24Slides:2.1-dev Feb 11, 2023
@dmyers dmyers deleted the patch-2 branch February 11, 2023 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not use the default database to create the "tenant"
2 participants