-
Notifications
You must be signed in to change notification settings - Fork 810
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
Error when user dont have any teams #188
Comments
Transferred to the jetstream repo. |
How do you login with a "non-team" user? All registered users receive teams on sign up. |
@taylorotwell Thanks for your reply, |
Encountered the same problem when I manually create user using factory (UserFactory.php). As for register, It's working fine for me. |
@sureyeahdie How can we create a user with team using factory ?? |
@iRajul the default factory doesn't handle other data creation, you need to create another factory that handles teams creation. Make sure you provide the factories with some static values, as the default UserFactory uses the Faker Library to populate data. More about factories and db seeding: |
I can see 2 issues here:
Both of these can be handled in code by the developer, but should they happen/be available by default? |
@taylorotwell, I want to give an example when creating a user without a team can be useful. |
Maybe someone will need a solution in the future:
/**
* Switch the user's context to the given team.
*
* @param $team
* @return bool
*/
public function switchTeam($team): bool
{
if (!$team || !$this->belongsToTeam($team)) {
return false;
}
$this->forceFill([
'current_team_id' => $team->id,
])->save();
$this->setRelation('currentTeam', $team);
return true;
}
<!-- Team Settings -->
<jet-dropdown-link
v-if="$page.props.user.current_team"
:href="route('teams.show', $page.props.user.current_team)"
>
Team Settings
</jet-dropdown-link> and <!-- Team Settings -->
<jet-responsive-nav-link
v-if="$page.props.user.current_team"
:href="route('teams.show', $page.props.user.current_team)"
:active="route().current('teams.show')"
>
Team Settings
</jet-responsive-nav-link> Perhaps I have not considered something else. |
I brought the teams into my laravel project but I am using this for agents and teams, not the users table. I updated the jetstream class file for the $userModel to reference 'App\Models\Agent" and changed the foreign_key to agent_id. The issue I have is when the HasTeams trait function pivots on the team_agent pivot table. It keeps looking for the team_user table. When I renamed the pivot table to team_user, it gets tripped up on my tenant_id in the where clause. That is a column in the pivot table for my multi-tenancy. Is there another way to configure the code to use the new pivot table name? |
You may try to add /**
* The table associated with the pivot model.
*
* @var string
*/
protected $table = 'team_user'; If you not have <?php
namespace App\Models;
use Laravel\Jetstream\Membership as JetstreamMembership;
class Membership extends JetstreamMembership
{
/**
* The table associated with the pivot model.
*
* @var string
*/
protected $table = 'team_agent';
} It's hard for me to understand without specific examples, but I hope I understood you correctly. |
That resolved my issue. Thanks! |
Description:
Added
use HasTeams;
to user modelsWhen login with a non-team user, it will show an error.
Steps To Reproduce:
I just start up and create 1 user using factory with data below:
and tried also register at register page.
after login to dashboard page, it will show
Trying to get property 'id' of non-object
that error at:
vendor/laravel/jetstream/src/HasTeams.php:28
The text was updated successfully, but these errors were encountered: