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

Do not hardcore model names #118

Closed
supertassu opened this issue Sep 9, 2020 · 3 comments
Closed

Do not hardcore model names #118

supertassu opened this issue Sep 9, 2020 · 3 comments

Comments

@supertassu
Copy link

Currently Jetstream.php has multiple hardcoded class names:

public static $userModel = 'App\\Models\\User';

return 'App\\Models\\Team';

return 'App\\Models\\Membership';

Could those be made configurable so the models can be located somewhere else (in a subdirectory, for example)? Thanks!

@mallardduck
Copy link
Contributor

@supertassu - I think you're overlooking the easiest way to address this issue. Extend and overwrite. There's nothing forcing you to use the Laravel\Jetstream\Jetstream class without customizing it and adjusting the behavior.

<?php


namespace App;

use App\SomeOther\Folder\User;

class MyJetstream extends \Laravel\Jetstream\Jetstream
{
    public static $userModel = User::class;

    /**
     * Get the name of the team model used by the application.
     *
     * @return string
     */
    public static function teamModel()
    {
        return 'App\\SomeOther\\Folder\\Team';
    }

    /**
     * Get the name of the team model used by the application.
     *
     * @return string
     */
    public static function membershipModel()
    {
        return 'App\\SomeOther\\Folder\\Membership';
    }
}

This will work just fine and all you need to change from here is to adjust your Apps JetstreamServiceProvider to use this implementation instead of the OOTB version shipped with the package.

@mallardduck
Copy link
Contributor

mallardduck commented Sep 9, 2020

@supertassu - now that #121 is merged in this should all be even easier to pull off.

I overlooked that a useUserModel method existed earlier, so between #119 and #121 this issue should be moot and can be set solved/closed.

Now you can simply do:

        Jetstream::useUserModel(App\MyStuf\Models\User::class);
        Jetstream::useTeamModel(App\MyStuf\Models\Team::class);
        Jetstream::useMembershipModel(App\MyStuf\Models\Membership::class);

... within the boot method of your apps JetstreamServiceProvider.

@supertassu
Copy link
Author

Thank you @mallardduck!

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

No branches or pull requests

2 participants