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

Create missing personalTeam, in cases where Teams feature was enabled later on. #108

Closed
wants to merge 1 commit into from

Conversation

michaelr0
Copy link

Hey there,

This error appears if Teams functionality isn't enabled from the get go, but is enabled at a later stage.

When trying to view the dashboard, I get the following error.
Trying to get property 'id' of non-object (View: /resources/views/layouts/app.blade.php)

Which appears to be the result of the User not having the default/personalTeam created for them, the following line then appears to trigger this error.
Auth::user()->currentTeam->id

I'm sure that there are a ton of different ways around this, this PR aims to resolve it by forcing a default Team to be created (if they don't already have one), anytime personalTeam is called. (currentTeam also calls personalTeam if the User does not have a team)

    /**
     * Get the user's "personal" team.
     *
     * @return \App\Team
     */
    public function personalTeam()
    {
        if ($this->ownedTeams->isEmpty()) {
            return $this->ownedTeams()->create([
                'name' => explode(' ', $this->name, 2)[0]."'s Team",
                'personal_team' => true,
            ]);
        }

        return $this->ownedTeams->where('personal_team', true)->first();
    }

@taylorotwell
Copy link
Member

Hmm, if you want to enable the team feature later on I suggest writing an Artisan command to create a team for each user in your system.

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.

2 participants